Constructor
new GameEngine(options)
Create a new GameEngine with the specified options.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | The options for the GameEngine, composed of the properties. |
Properties:
Name | Type | Description |
---|---|---|
targetId |
string | The DOM id of the element to target. This element will be replaced with a HTML5 'canvas' element. |
fullscreen |
boolean | Allow the canvas element to occupy the maximum possible space (optional, default false) |
showHUD |
boolean | Show the debug Heads Up Display (HUD) (optional, default false) |
x |
integer | The viewport x-coordinate in pixels (optional, default 0) |
y |
integer | The viewport y-coordinate in pixels (optional, default 0) |
scale |
float | The current scale (zoom) where 1 = 100% (optional, default 1) |
minX |
integer | The minimum viewport x-coordinate in pixels (optional) |
minY |
integer | The minimum viewport y-coordinate in pixels (optional) |
maxX |
integer | The maximum viewport x-coordinate in pixels (optional) |
maxY |
integer | The maximum viewport y-coordinate in pixels (optional) |
globalAlpha |
float | The global alpha value (0 to 1) for drawing scenes (optional, default 1) |
enableScroll |
boolean | Enable mouse scrolling (optional, default true) |
enableZoom |
boolean | Enable mouse zooming (optional, default true) |
width |
integer | The width of the viewport in pixels (readonly) |
height |
integer | The height of the viewport in pixels (readonly) |
- Mixes In:
- Source:
Example
To create a GameEngine attached to a specified element in HTML5
<div id='game' width="1200" height="960"></div>
<script type="text/javascript">
const GameEngine = require('GameEngine')
var game = new GameEngine({ targetId: 'game', fullscreen: true, showHUD: true });
game.start();
</script>
Extends
Methods
addAsset(name, src)
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Asset Name |
src |
String | Source filename |
- Source:
addAudio(name, src, type)
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Audio Name |
src |
String | Source filename |
type |
String | MIME type |
- Source:
addEventListener(event, fn)
addEventListener is an alias of HasEventsMixin#on
Parameters:
Name | Type | Description |
---|---|---|
event |
String | The name of the event |
fn |
function | The event handler |
- Overrides:
- Source:
Throws:
-
'unon: no such event
' if event not defined - Type
- Exception
bootElement(callback)
Boot the GameEngine into an HTML 'canvas' element, and replace the DOM element specified by GameEngine.targetId with it
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when the element has been replaced (optional) |
- Source:
defineEvent(event)
Add the given event.
Parameters:
Name | Type | Description |
---|---|---|
event |
Array.<String> | The event name to add |
- Overrides:
- Source:
defineEvents(events)
Add the given events.
Parameters:
Name | Type | Description |
---|---|---|
events |
Array.<String> | The event names to add |
- Overrides:
- Source:
getAsset(name) → {Asset}
Get the Asset with the specified name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Asset Name |
- Source:
Throws:
-
Will throw 'Asset not found' if the Asset has not been loaded
- Type
- Exception
Returns:
The Asset with the specified name, or null
- Type
- Asset
getAudio(name) → {Audio}
Get the Audio with the specified name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Audio Name |
- Source:
Throws:
-
Will throw 'Audio not found' if the Audio has not been loaded
- Type
- Exception
Returns:
The Audio with the specified name, or null
- Type
- Audio
getEventListeners() → {Array.<function()>}
Return an array of the handlers for the given event.
- Overrides:
- Source:
Throws:
-
'getEventListeners: no such event
' if event not defined - Type
- Exception
Returns:
The handler Functions for the event
- Type
- Array.<function()>
init(callback)
Init is called after asset and audio loading. You should override init to create your Scenes, Entities and other game objects.
Note: If you override init, you *must* call the callback when done.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when the init has been completed |
- Source:
loadAssets(callback)
Create and Load all defined Assets.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when all assets have been loaded (optional) |
- Source:
loadAudio(callback)
Create and Load all defined Audios.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when all assets have been loaded (optional) |
- Source:
on(event, fn)
Add the given handler to the event.
Parameters:
Name | Type | Description |
---|---|---|
event |
String | The name of the event |
fn |
function | The event handler |
- Overrides:
- Source:
Throws:
-
'unon: no such event
' if event not defined - Type
- Exception
recomputeFullScreen()
Recompute the width and height from the 'canvas' element dimensions and call redraw()
- Source:
redraw()
Mark the whole GameEngine to be redrawn.
- Source:
removeEventListener(event, fn)
removeEventListener is an alias of HasEventsMixin#on
Parameters:
Name | Type | Description |
---|---|---|
event |
String | The name of the event |
fn |
function | The event handler |
- Overrides:
- Source:
Throws:
-
'unon: no such event
' if event not defined - Type
- Exception
setGlobalAlpha(ga)
Set the global alpha for drawing.
Parameters:
Name | Type | Description |
---|---|---|
ga |
float | The Global alpha value 0 - 1 |
- Source:
start(callback)
Start the game, loading all Assets and Audios defined by addAsset() and addAudio(), bind to the HTML element, call init() and start the renderer.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when the game has been started (optional) |
- Source:
stop()
Stop the game engine.
- Source:
trigger(event, …args)
Trigger the given event with the specified arguments. Handlers are queued for execution using setImmediate().
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event |
String | The name of the event | |
args |
* |
<repeatable> |
The event arguments |
- Overrides:
- Source:
Throws:
-
'trigger: no such event
' if event not defined - Type
- Exception
undefineEvent(event)
Remove the given event.
Parameters:
Name | Type | Description |
---|---|---|
event |
Array.<String> | The event name to remove |
- Overrides:
- Source:
undefineEvents(events)
Remove the given events.
Parameters:
Name | Type | Description |
---|---|---|
events |
Array.<String> | The event names to remove |
- Overrides:
- Source:
unon(event, fn)
Remove the given handler from the event.
Parameters:
Name | Type | Description |
---|---|---|
event |
String | The name of the event |
fn |
function | The event handler |
- Overrides:
- Source:
Throws:
-
'unon: no such event
' if event not defined - Type
- Exception