Coder Social home page Coder Social logo

littlejs's Introduction

LittleJS Logo LittleJS - The Tiny JavaScript Game Engine That Can

All aboard!

LittleJS is a super lightweight JavaScript game engine designed for modern web development. With its fast hybrid rendering system, it offers a comprehensive suite of game development tools from rendering to sound effects. The code is very clean and well documented with a variety of examples to get you started. Choo-Choo! ๐Ÿš‚

LittleJS Screenshot

Demos

Starter Project - Clean example with only a few things to get you started

Puzzle Game - Match 3 puzzle game with HD rendering and high score tracking

Platformer - Platformer/shooter with procedural generation and destruction

Breakout - Breakout game with post processing effect

Stress Test - Max sprite/object test and music system demo

Particle System Designer - Particle system editor and visualizer

About LittleJS

LittleJS is a small but powerful game engine with many features and no depenencies.

Graphics

  • Fast sprite and tile map rendering engine with WebGL
  • Update and render 10,000+ objects at 60fps, often many times more
  • Apply Shadertoy compatible shaders for post processinge effects

Audio

  • Positional sound effects with ZzFX sound effect generator
  • Music with ZzFXM, mp3, or wav audio

Input

  • Input processing system for keyboard, mouse, gamepad, and touch
  • On screen touch gamepad for mobile devices

Physics

  • Kinematic physics object update
  • 2D physics engine with collision handling for axis aligned boxes
  • Very fast collision handling for tile maps

Flexability

  • Designed to work with all modern web bowsers and mobile devices
  • Compatible with TypeScript and includes an example TS project
  • For size coding competitions like js13kGames, starter project builds to a 7KB zip file
  • Build to a Windows executable with Electron for distribution on platforms like Steam
  • Open Source with the MIT license so it can be used for anything you want

Extra Systems

  • Debug rendering system
  • Particle effects system and design tool
  • Bitmap font rendering and includes a built in engine font
  • Medal system tracks and displays achievements with Newgrounds integration

How to use LittleJS

To use LittleJS download the latest package from GitHub or call npm install littlejsengine. This package contains the engine and several small examples.

You can use the empty example template as a starting point. This file contains just the minimal setup to start the engine. You can also download and include littlejs.js or littlejs.min.js.

If your game loads any files like images you will need to run a local web server. I recommend an editor that does this automatically like Visual Studio Code with the Live Server plugin. You can also use http-server via npm.

Tutorial

Builds

To easily include LittleJS in your game, you can use one of the 3 pre-built js files. These are also built automatically by the build scripts.

LittleJS can also be imported as a module. There are two module flavors that are automatically built.

To rebuild the engine you must first run npm install to setup the necessary npm dependencies. Then call npm run build to build the engine.

The starter project example also includes a node js file build.js that compresses everything into a tiny zip file using Google Closure, UglifyJS, Roadroller, and ECT.

LittleJS Setup

To start LittleJS, you must create 5 functions and pass them to engineInit. A canvas will automatically be created and added to the document.

function gameInit()
{
    // called once after the engine starts up
    // setup the game
}

function gameUpdate()
{
    // called every frame at 60 frames per second
    // handle input and update the game state
}

function gameUpdatePost()
{
    // called after physics and objects are updated
    // setup camera and prepare for render
}

function gameRender()
{
    // called before objects are rendered
    // draw any background effects that appear behind objects
}

function gameRenderPost()
{
    // called after objects are rendered
    // draw effects or hud that appear above all objects
}

// Startup LittleJS Engine
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');

LittleJS Objects

Though not required, LittleJS is intended to be used as an object oriented system by extending the base class EngineObject with your own. This lightweight class provides many useful features including physics, collision, parent/child system, and sorted rendering. Engine objects are automatically added to the global list of objects where they will be updated and rendered until destroyed.

Here is a template you can use to make objects that behave however you want. See the examples for a complete demonstration.

class MyObject extends EngineObject 
{
    constructor(pos, size, tileIndex, tileSize, angle)
    {
        super(pos, size, tileIndex, tileSize, angle);
    }

    update()
    {
        // update object physics and position
        super.update(); 
    }

    render()
    {
        // draw object as a sprite
        super.render();
    }
}

Engine Source Code

This engine is made with simplicity in mind using clean easy to read code. There are only a few files used by the entire engine.

Optional Components, these components are built to synergize with the rest of the engine but are not necessary.

Debugging

Debug builds of LittleJS have a special menu that can be opened by pressing the Esc key.

  • Esc: Debug Overlay
  • 1: Debug Physics
  • 2: Debug Particles
  • 3: Debug Gamepads
  • 4: God Mode
  • 5: Save Screenshot

Games Made With LittleJS

Here are a few of the amazing games people are making with LittleJS.

LittleJS Logo

littlejs's People

Contributors

bajuba avatar jwigert avatar killedbyapixel avatar lopis avatar lukenickerson avatar matthijsgroen avatar moreiramirakulo avatar paxperscientiam avatar pebutler3 avatar someunusualgames avatar thatonebro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.