Class Engine extends MessageDispatcher
The Black class represents the core of the Black Engine.Methods
Engine(containerElementId, gameClass, videoDriverClass, systemClasses) constructor
Creates a new Black instance.
First parameter has to be a id of the HTML div element the game will be rendered to.
Second parameter has to be
Third parameter has to be a class name of
Fourth parameter is optional array of System to use,
Parameters
Creates a new Black instance.
First parameter has to be a id of the HTML div element the game will be rendered to.
Second parameter has to be
GameObject
class which will be the root object of your application.Third parameter has to be a class name of
VideoNullDriver
subclass eg CanvasDriver
.Fourth parameter is optional array of System to use,
Parameters
containerElementId : string — The id of an DOM element.
gameClass : function — Type name of an GameObject to start execution from.
videoDriverClass : function — Type name of an VideoDriver (VideoNullDriver, DOMDriver or CanvasDriver)
systemClasses : Array.<function(new:System)> — The list of systems to be initialized with Black engine.
gameClass : function — Type name of an GameObject to start execution from.
videoDriverClass : function — Type name of an VideoDriver (VideoNullDriver, DOMDriver or CanvasDriver)
systemClasses : Array.<function(new:System)> — The list of systems to be initialized with Black engine.
pause() method
Pauses all engine update logic. Note: RAF is not going to be paused and will work in background.
Pauses all engine update logic. Note: RAF is not going to be paused and will work in background.
resume() method
Resumes update execution.
Resumes update execution.
getSystem(typeName) method
Gets system by type.
Parameters
System | null — The `System` instance or null if not found.
Gets system by type.
Parameters
typeName : function — The system type.
ReturnsSystem | null — The `System` instance or null if not found.
start() method
Boots up the engine!
Boots up the engine!
stop() method
Stops any executions, destroys resources and scene.
Stops any executions, destroys resources and scene.
destroy() method
Destroys the whole thing!
Destroys the whole thing!
onTagUpdated(child, oldTag, newTag) method
Called when tag changed for specific
Parameters
void
Called when tag changed for specific
GameObject
.
Parameters
child : GameObject — A game object fired the event.
oldTag : string | null — Old tag.
newTag : string | null — New tag.
ReturnsoldTag : string | null — Old tag.
newTag : string | null — New tag.
void
onChildrenAdded(child) method
Called when specific game object is added to display list.
Called when specific game object is added to display list.
onChildrenChanged(child) method
Called when specific game object is changed its index in display list.
Called when specific game object is changed its index in display list.
onChildrenRemoved(child) method
Called when specific game object is added to display list.
Called when specific game object is added to display list.
onComponentAdded(child, component) method
Called when specific component is added to GameObject instance.
Parameters
void
Called when specific component is added to GameObject instance.
Parameters
child : GameObject — Instance of GameObject.
component : Component — Instance of Component added to game object.
Returnscomponent : Component — Instance of Component added to game object.
void
onComponentRemoved(child, component) method
Called when specific component is removed from its owner.
Parameters
void
Called when specific component is removed from its owner.
Parameters
child : GameObject — Instance of GameObject.
component : Component — Instance of Component removed from game object.
Returnscomponent : Component — Instance of Component removed from game object.
void
Inherited Methods
on(name, callback, context) inherited method
Adds listener by given name and callback.
Parameters
MessageBinding
Adds listener by given name and callback.
Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as
Returnscallback : function — Function to be called on message send.
context : * — Object to be used as
this
in callback function. MessageBinding
off(names) inherited method
Removes all bindings by given message name.
Parameters
void
Removes all bindings by given message name.
Parameters
names : string — One or more message name.
Returnsvoid
once(name, callback, context) inherited method
Adds listener by given name and callback. Binding will be automatically removed after first execution.
Parameters
MessageBinding
Adds listener by given name and callback. Binding will be automatically removed after first execution.
Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as
Returnscallback : function — Function to be called on message send.
context : * — Object to be used as
this
in callback function. MessageBinding
post(name, params) inherited method
Posts message with a given params.
Adding
Parameters
void
Posts message with a given params.
Adding
~
character to the begging of the name will bubble message to the top of the tree.Parameters
name : string — The name of a message
params : * — A list of params to send
Returnsparams : * — A list of params to send
void
Properties
viewport : Viewport property
Returns the current viewport instance. Used to get size of a game screen, or listen for resize messages.
Returns the current viewport instance. Used to get size of a game screen, or listen for resize messages.
pauseOnHide : boolean property
Gets/Sets if engine should be automatically paused when window is hidden.
Gets/Sets if engine should be automatically paused when window is hidden.
pauseOnBlur : boolean property
Gets/Sets if engine should be automatically paused when container element is blurred.
Gets/Sets if engine should be automatically paused when container element is blurred.
useHiDPR : boolean property
Gets/sets whenever driver should be created with high DPR support.
NOTE: Cannot be changed at runtime.
Gets/sets whenever driver should be created with high DPR support.
NOTE: Cannot be changed at runtime.
Inherited Properties
path : string | null inherited property
Returns string representing a url like path to this object in the display
tree.
Returns string representing a url like path to this object in the display
tree.
Messages
looped message
Posted when engine is not able to achieve desired amount of updates per second.
Usually happens when user switches to another tab in browser or update logic is too heavy to be executed
withing one update loop. Lowering
Increasing
Posted when engine is not able to achieve desired amount of updates per second.
Usually happens when user switches to another tab in browser or update logic is too heavy to be executed
withing one update loop. Lowering
Black.ups
value can help if update is heavy. Increasing
Black.maxUpdatesPerFrame
can lead to dead lock.