Class GameObject extends MessageDispatcher
Building block in Black Engine.Methods
GameObject() constructor
Creates new instance of GameObject.
Creates new instance of GameObject.
checkStatic(includeChildren) method
Returns true if object was clean for at least 1 update.
Note: Make sure to apply all changes to this game object before checking for static.
Parameters
boolean
Returns true if object was clean for at least 1 update.
Note: Make sure to apply all changes to this game object before checking for static.
Parameters
includeChildren : boolean
Returnsboolean
onAdded() method
This method called each time object added to stage.
This method called each time object added to stage.
onRemoved() method
Called when object is removed from stage.
Called when object is removed from stage.
add(gameObjectsAndOrComponents) method
Sugar method for adding child
Parameters
GameObject — This game object
Sugar method for adding child
GameObjects
or Components
in a simple manner.
Parameters
gameObjectsAndOrComponents : GameObject | Component — A
ReturnsGameObject
or Component
to add. GameObject — This game object
addChild(child) method
Adds a child
children in this GameObject instance.
Parameters
GameObject
Adds a child
GameObject
instance to this GameObject
instance. The child is added to the top of all other children in this GameObject instance.
Parameters
child : GameObject — The GameObject instance to add as a child of this GameObject instance.
ReturnsGameObject
addChildAt(child, index) method
Adds a child
children in this GameObject instance.
Parameters
GameObject — The GameObject instance that you pass in the child parameter.
Adds a child
GameObject
instance to this GameObject
instance. The child is added to the top of all other children in this GameObject instance.
Parameters
child : GameObject — The GameObject instance to add as a child of this GameObject instance.
index : number — The index position to which the child is added.
Returnsindex : number — The index position to which the child is added.
GameObject — The GameObject instance that you pass in the child parameter.
setChildIndex(child, index) method
Sets the index (layer) of the specified
Sets the index (layer) of the specified
GameObject
to the specified index (layer).
removeChild(child) method
Removes specified child
Removes specified child
GameObject
instance from children.
getChildByName(name) method
Finds children by name.
Parameters
GameObject | null — GameObject instance or null if not found.
Finds children by name.
Parameters
name : string — Name of the child object to find.
ReturnsGameObject | null — GameObject instance or null if not found.
getChildAt(index) method
Returns
Parameters
GameObject — The `GameObject` at specified index.
Returns
GameObject
at specified index.
Parameters
index : number — The index of child
ReturnsGameObject
. GameObject — The `GameObject` at specified index.
addComponent(component) method
Adds Component instance to the end of the list.
Adds Component instance to the end of the list.
addComponentAt(component, index) method
Adds Component to the list at given position.
Adds Component to the list at given position.
removeComponent(instance) method
Remove specified component.
Remove specified component.
getComponent(typeName) method
Get component by type.
Parameters
Component | null — The `Component` instance or null if not found.
Get component by type.
Parameters
typeName : function — The component type.
ReturnsComponent | null — The `Component` instance or null if not found.
onUpdate() method
Called at every engine update. The execution order of onFixedUpdate, onUpdate and onPostUpdate is
going from top to bottom of the display list.
Called at every engine update. The execution order of onFixedUpdate, onUpdate and onPostUpdate is
going from top to bottom of the display list.
onGetLocalBounds(outRect) method
Override this method if you need to specify GameObject size. Should be always be a local coordinates.
Override this method if you need to specify GameObject size. Should be always be a local coordinates.
getBounds(space, includeChildren, outRect) method
Returns world bounds of this object and all children if specified (true by default).
Parameters
Rectangle — Returns bounds of the object with/without all children.
Returns world bounds of this object and all children if specified (true by default).
object.getBounds()
- relative to parent (default).object.getBounds(object)
- local bounds.object.getBounds(object.parent)
- relative to parent.object.getBounds(objectB)
- relative to objectB space.Parameters
space : GameObject — The
includeChildren : boolean — Specifies if include children in calculations.
outRect : Rectangle — Rectangle to be returned.
ReturnsGameObject
relative to. includeChildren : boolean — Specifies if include children in calculations.
outRect : Rectangle — Rectangle to be returned.
Rectangle — Returns bounds of the object with/without all children.
getStageBounds(outRect) method
Returns stage relative bounds of this object excluding it's children;
Returns stage relative bounds of this object excluding it's children;
hitTest(localPoint) method
Evaluates whether the game object or one of its children intersects with the given point
Evaluates whether the game object or one of its children intersects with the given point
setTransform(x, y, r, scaleX, scaleY, anchorX, anchorY, includeChildren) method
Sets the object transform in one line.
Parameters
GameObject — This.
Sets the object transform in one line.
Parameters
x : number — Cord X.
y : number — Cord Y.
r : number — Rotation.
scaleX : number — Scale X.
scaleY : number — Scale Y.
anchorX : number — Anchor X.
anchorY : number — Anchor Y.
includeChildren : boolean — Include children when adjusting pivot?
Returnsy : number — Cord Y.
r : number — Rotation.
scaleX : number — Scale X.
scaleY : number — Scale Y.
anchorX : number — Anchor X.
anchorY : number — Anchor Y.
includeChildren : boolean — Include children when adjusting pivot?
GameObject — This.
relativeTo(gameObject, outVector) method
Calculates GameObject's position relative to another GameObject.
Calculates GameObject's position relative to another GameObject.
localToGlobal(localPoint, outVector) method
Calculate global position of the object.
Calculate global position of the object.
globalToLocal(globalPoint, outVector) method
Calculate local position of the object
Calculate local position of the object
alignAnchor(ax, ay) method
Sets the origin point relatively to its bounds. For example, setting x and y value to 0.5 will set origin to the
center of the object.
Parameters
GameObject — This.
Sets the origin point relatively to its bounds. For example, setting x and y value to 0.5 will set origin to the
center of the object.
Parameters
ax : number — Align along x-axis.
ay : number — Align along y-axis.
Returnsay : number — Align along y-axis.
GameObject — This.
alignPivot(ax, ay) method
Sets anchor point to given position. See
Parameters
GameObject — This.
Sets anchor point to given position. See
alignPivotOffset
.
Parameters
ax : number — Align along x-axis.
ay : number — Align along y-axis.
Returnsay : number — Align along y-axis.
GameObject — This.
alignPivotOffset(ax, ay, includeChildren) method
Sets the origin point offset from current anchor value. For example, setting anchor-x value to 0.5 and pivotOffsetX
to 10 will center object by x-axis and will shift object to the left by 10 pixels from half of the width.
Parameters
GameObject — This.
Sets the origin point offset from current anchor value. For example, setting anchor-x value to 0.5 and pivotOffsetX
to 10 will center object by x-axis and will shift object to the left by 10 pixels from half of the width.
Parameters
ax : number — Align along x-axis.
ay : number — Align along y-axis.
includeChildren : boolean — Include children elements when calculating bounds?
Returnsay : number — Align along y-axis.
includeChildren : boolean — Include children elements when calculating bounds?
GameObject — This.
spawn(gen, ctx) method
Starts coroutine.
Parameters
*
Starts coroutine.
Parameters
gen : function — Generator function.
ctx : * — Context for Generator function.
Returnsctx : * — Context for Generator function.
*
wait(seconds) method
Waits for given amount of seconds before processing.
Parameters
function
Waits for given amount of seconds before processing.
Parameters
seconds : number — Duration
Returnsfunction
waitMessage(message) method
Waits for a specific message.
Parameters
function
Waits for a specific message.
Parameters
message : string — The name of the message to wait for.
Returnsfunction
setDirty(flag, includeChildren) method
Marks this GameObject and/or its children elements as dirty.
Parameters
void
Marks this GameObject and/or its children elements as dirty.
Parameters
flag : DirtyFlag — The flag or flag bit mask.
includeChildren : boolean — Specifies if the flag needed for all children.
ReturnsincludeChildren : boolean — Specifies if the flag needed for all children.
void
setParentDirty(flag) method
Marks the GameObject's parent as dirty.
Parameters
void
Marks the GameObject's parent as dirty.
Parameters
flag : DirtyFlag — The flag or flag bit mask.
Returnsvoid
setTransformDirty() method
Marks this GameObject as Local dirty and all children elements as World dirty.
Marks this GameObject as Local dirty and all children elements as World dirty.
setRenderDirty() method
Marks this GameObject with Render dirty flag if it is not suspended for dirty.
Marks this GameObject with Render dirty flag if it is not suspended for dirty.
intersects(gameObject, point) static method
Returns whenever a given GameObject intersects with a point.
Parameters
Returns
boolean — True if intersects.
Returns whenever a given GameObject intersects with a point.
Parameters
Returns
boolean — True if intersects.
intersectsAt(gameObject, point, outVector) static method
Returns a point where intersection were made in local space.
Parameters
boolean — True if intersects.
Returns a point where intersection were made in local space.
Parameters
gameObject : GameObject — GameObject to test intersection with.
point : Vector — The point to test.
outVector : Vector — If passed point of intersection will be stored in it.
Returnspoint : Vector — The point to test.
outVector : Vector — If passed point of intersection will be stored in it.
boolean — True if intersects.
intersectsWith(gameObject, point) static method
Checks if GameObject or any of its children elements intersects the given point.
Checks if GameObject or any of its children elements intersects the given point.
findWithTag(tag) static method
Returns all GameObject with given tag.
Parameters
Array. | null — Array of GameObject or null if not found.
Returns all GameObject with given tag.
Parameters
tag : string — Tag to find.
ReturnsArray.
findComponents(gameObject, type) static method
Returns a list of Components.
Parameters
Returns
Array. — Array of Component or empty array.
Returns a list of Components.
Parameters
Returns
Array.
forEach(gameObject, action) static method
Runs action across all GameObjects.
Parameters
void
Runs action across all GameObjects.
Parameters
gameObject : GameObject — GameObject to start iteration from.
action : function — The function to be executed on every GameObject.
Returnsaction : function — The function to be executed on every GameObject.
void
find(name, node) static method
Finds object by its name. If node is not passed the root will be taken as
starting point.
Finds object by its name. If node is not passed the root will be taken as
starting point.
findById(id, node) static method
Finds object by its id property. If node is not passed the root will be taken as
starting point.
Finds object by its id property. If node is not passed the root will be taken as
starting point.
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
worldTransformation : Matrix property
Gets cloned Matrix object which represents object orientation in world space.
Gets cloned Matrix object which represents object orientation in world space.
worldTransformationInverted : Matrix property
Returns cloned and inverted Matrix object which represents object orientation in world space
Returns cloned and inverted Matrix object which represents object orientation in world space
x : number property
Gets/Sets the x coordinate of the GameObject instance relative to the local coordinates of the parent GameObject.
Gets/Sets the x coordinate of the GameObject instance relative to the local coordinates of the parent GameObject.
y : number property
Gets/Sets the y coordinate of the GameObject instance relative to the local coordinates of the parent GameObject.
Gets/Sets the y coordinate of the GameObject instance relative to the local coordinates of the parent GameObject.
pivotOffsetX : number property
Gets/Sets the x coordinate of the object's origin in its local space in pixels.
Gets/Sets the x coordinate of the object's origin in its local space in pixels.
pivotOffsetY : number property
Gets/Sets the y coordinate of the object's origin in its local space in pixels.
Gets/Sets the y coordinate of the object's origin in its local space in pixels.
localWidth : number property
Returns width of this GameObject in local space without including children
elements.
Returns width of this GameObject in local space without including children
elements.
localHeight : number property
Returns height of this GameObject in local space without including children
elements.
Returns height of this GameObject in local space without including children
elements.
Inherited Properties
stage : Stage | null inherited property
Returns the stage Game Object to which this belongs to or null if not added onto stage.
Returns the stage Game Object to which this belongs to or null if not added onto stage.
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.