Engine

LittleJS - The Tiny JavaScript Game Engine That Can! MIT License - Copyright 2021 Frank Force

Engine Features

  • Object oriented system with base class engine object
  • Base class object handles update, physics, collision, rendering, etc
  • Engine helper classes and functions like Vector2, Color, and Timer
  • Super fast rendering system for tile sheets
  • Sound effects audio with zzfx and music with zzfxm
  • Input processing system with gamepad and touchscreen support
  • Tile layer rendering and collision system
  • Particle effect system
  • Medal system tracks and displays achievements
  • Debug tools and debug rendering system
  • Post processing effects
  • Call engineInit() to start it up!

Members

(static, constant) engineName :String

Name of engine

Type:
  • String
Default Value
  • LittleJS

(static) engineObjects :Array

Array containing all engine objects

Type:
  • Array

(static) engineObjectsCollide :Array

Array containing only objects that are set to collide with other objects this frame (for optimization)

Type:
  • Array

(static, constant) engineVersion :String

Version of engine

Type:
  • String
Default Value
  • 1.8.1

(static) frame :Number

Current update frame, used to calculate time

Type:
  • Number

(static, constant) frameRate :Number

Frames per second to update objects

Type:
  • Number
Default Value
  • 60

(static) paused :Boolean

Is the game paused? Causes time and objects to not be updated

Type:
  • Boolean
Default Value
  • 0

(static) time :Number

Current engine time since start in seconds, derived from frame

Type:
  • Number

(static, constant) timeDelta :Number

How many seconds each frame lasts, engine uses a fixed time step

Type:
  • Number
Default Value
  • 1/60

(static) timeReal :Number

Actual clock time since start in seconds (not affected by pause or frame rate clamping)

Type:
  • Number

Methods

(static) engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSourcesopt)

Start up LittleJS engine with your callback functions

Parameters:
NameTypeAttributesDefaultDescription
gameInitfunction

Called once after the engine starts up, setup the game

gameUpdatefunction

Called every frame at 60 frames per second, handle input and update the game state

gameUpdatePostfunction

Called after physics and objects are updated, setup camera and prepare for render

gameRenderfunction

Called before objects are rendered, draw any background effects that appear behind objects

gameRenderPostfunction

Called after objects are rendered, draw effects or hud that appear above all objects

imageSourcesString<optional>
'tiles.png'

Image to load

(static) engineObjectsCallback(posopt, sizeopt, callbackFunctionopt, objectsopt)

Triggers a callback for each object within a given area

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

Center of test area

sizeNumber<optional>

Radius of circle if float, rectangle size if Vector2

callbackFunctionfunction<optional>

Calls this function on every object that passes the test

objectsArray<optional>
engineObjects

List of objects to check

(static) engineObjectsDestroy()

Destroy and remove all objects

(static) engineObjectsUpdate()

Update each engine object, remove destroyed objects, and update time

(static) setPaused(paused)

Set if game is paused

Parameters:
NameTypeDescription
pausedBoolean