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!
- Source
Members
(static, constant) engineName :string
Name of engine
- string
- Default Value
- LittleJS
- Source
(static) engineObjects :Array.<EngineObject>
Array containing all engine objects
- Array.<EngineObject>
- Source
(static) engineObjectsCollide :Array.<EngineObject>
Array with only objects set to collide with other objects this frame (for optimization)
- Array.<EngineObject>
- Source
(static, constant) engineVersion :string
Version of engine
- string
- Default Value
- 1.11.10
- Source
(static) frame :number
Current update frame, used to calculate time
- number
- Source
(static, constant) frameRate :number
Frames per second to update
- number
- Default Value
- 60
- Source
(static) paused :boolean
Is the game paused? Causes time and objects to not be updated
- boolean
- Default Value
- false
- Source
(static) time :number
Current engine time since start in seconds
- number
- Source
(static, constant) timeDelta :number
How many seconds each frame lasts, engine uses a fixed time step
- number
- Default Value
- 1/60
- Source
(static) timeReal :number
Actual clock time since start in seconds (not affected by pause or frame rate clamping)
- number
- Source
Methods
(static) engineAddPlugin(updateFunctionopt, renderFunctionopt)
Add a new update function for a plugin
Name | Type | Attributes | Description |
---|---|---|---|
updateFunction | function | <optional> | |
renderFunction | function | <optional> |
- Source
(static) engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSourcesopt, rootElementopt)
Startup LittleJS engine with your callback functions
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
gameInit | function | | Called once after the engine starts up | ||
gameUpdate | function | Called every frame before objects are updated | ||
gameUpdatePost | function | Called after physics and objects are updated, even when paused | ||
gameRender | function | Called before objects are rendered, for drawing the background | ||
gameRenderPost | function | Called after objects are rendered, useful for drawing UI | ||
imageSources | Array.<string> | <optional> | [] | List of images to load |
rootElement | HTMLElement | <optional> | Root element to attach to, the document body by default |
- Source
(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 | Vector2 | | <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.<EngineObject> | <optional> | engineObjects | List of objects to check |
- Source
(static) engineObjectsCollect(posopt, sizeopt, objectsopt) → {Array.<EngineObject>}
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 | Vector2 | | <optional> | Radius of circle if float, rectangle size if Vector2 | |
objects | Array.<EngineObject> | <optional> | engineObjects | List of objects to check |
- Source
- List of collected objects
- Type:
- Array.<EngineObject>
(static) engineObjectsDestroy()
Destroy and remove all objects
- Source
(static) engineObjectsRaycast(start, end, objectsopt) → {Array.<EngineObject>}
Return a list of objects intersecting a ray
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start | Vector2 | |||
end | Vector2 | |||
objects | Array.<EngineObject> | <optional> | engineObjects | List of objects to check |
- Source
- List of objects hit
- Type:
- Array.<EngineObject>
(static) engineObjectsUpdate()
Update each engine object, remove destroyed objects, and update time
- Source
(static) setPaused(isPaused)
Set if game is paused
Name | Type | Description |
---|---|---|
isPaused | boolean |
- Source