LittleJS - The Tiny Fast JavaScript Game Engine 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
- String
- Default Value
- LittleJS
(static) engineObjects :Array
Array containing all engine objects
- Array
(static) engineObjectsCollide :Array
Array with only objects set to collide with other objects this frame (for optimization)
- Array
(static, constant) engineVersion :String
Version of engine
- String
- Default Value
- 1.9.8
(static) frame :Number
Current update frame, used to calculate time
- Number
(static, constant) frameRate :Number
Frames per second to update
- Number
- Default Value
- 60
(static) paused :Boolean
Is the game paused? Causes time and objects to not be updated
- Boolean
- Default Value
- false
(static) time :Number
Current engine time since start in seconds
- Number
(static, constant) timeDelta :Number
How many seconds each frame lasts, engine uses a fixed time step
- Number
- Default Value
- 1/60
(static) timeReal :Number
Actual clock time since start in seconds (not affected by pause or frame rate clamping)
- Number
Methods
(static) addPluginRender(renderFunction)
Add a new render function for a plugin
Name | Type | Description |
---|---|---|
renderFunction | function |
(static) addPluginUpdate(updateFunction)
Add a new update function for a plugin
Name | Type | Description |
---|---|---|
updateFunction | function |
(static) engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSourcesopt)
Startup LittleJS engine with your callback functions
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
gameInit | function | Called once after the engine starts up, setup the game | ||
gameUpdate | function | Called every frame at 60 frames per second, handle input and update the game state | ||
gameUpdatePost | function | Called after physics and objects are updated, setup camera and prepare for render | ||
gameRender | function | Called before objects are rendered, draw any background effects that appear behind objects | ||
gameRenderPost | function | Called after objects are rendered, draw effects or hud that appear above all objects | ||
imageSources | Array | <optional> | ['tiles.png'] | Image to load |
(static) engineObjectsCallback(posopt, sizeopt, callbackFunctionopt, objectsopt)
Triggers a callback for each object within a given area
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | <optional> | Center of test area, or undefined for all objects | |
size | Number | | <optional> | Radius of circle if float, rectangle size if Vector2 | |
callbackFunction | function | <optional> | Calls this function on every object that passes the test | |
objects | Array | <optional> | engineObjects | List of objects to check |
(static) engineObjectsCollect(posopt, sizeopt, objectsopt) → {Array}
Collects all object within a given area
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | <optional> | Center of test area, or undefined for all objects | |
size | Number | | <optional> | Radius of circle if float, rectangle size if Vector2 | |
objects | Array | <optional> | engineObjects | List of objects to check |
- List of collected objects
- Type:
- Array
(static) engineObjectsDestroy()
Destroy and remove all objects
(static) engineObjectsRaycast(start, end, objectsopt) → {Array}
Return a list of objects intersecting a ray
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start | Vector2 | |||
end | Vector2 | |||
objects | Array | <optional> | engineObjects | List of objects to check |
- List of objects hit
- Type:
- Array
(static) engineObjectsUpdate()
Update each engine object, remove destroyed objects, and update time
(static) setPaused(isPaused)
Set if game is paused
Name | Type | Description |
---|---|---|
isPaused | Boolean |