Grape.GameObject Class
A GameObject is an object which can be added to a layer, and can subscribe to the layer's events with the onGlobal() method or the global-event keyword.
Constructor
Grape.GameObject
()
Item Index
Methods
Events
Methods
addTag
-
name
Adds a tag to a taggable object.
Parameters:
-
name
StringTag name
Returns:
true, if a new tag is added, false, if the tag was already added.
emit
-
event
-
payload
Emits an event to the instance: calls all event listeners subscribed to this event, or the 'any' event.
Parameters:
-
event
StringEvent
-
payload
An object passed as parameter to all event listeners.
getGame
()
Grape.Game | Null
Gets the current game instance through the current layer.
Returns:
The current game, or null, if the lookup fails.
getScene
()
Grape.Scene | Null
Gets the root layer.
Returns:
The root layer, or null, if the lookup fails.
hasTag
-
name
Checks if a tag is added or not.
Parameters:
-
name
StringTag name
Returns:
true, if the instance has the tag
off
-
event
-
listener
Unsubscribes from an event.
Parameters:
-
event
StringEvent
-
listener
FunctionEvent listener
on
-
event
-
listener
Subscribes to an event. The event handler will be called with this instance as context.
Parameters:
-
event
StringThe event to subscribe
-
listener
FunctionEvent listener
onGlobal
-
event
-
handler
Subscribes to an event on the layer the instance is added to. If the instance is not yet added to any layers, it will subscribe when added.
Parameters:
-
event
StringEvent
-
handler
FunctionEvent listener
remove
()
Removes the instance from the layer.
removeTag
-
name
Removes a tag from a taggable object. If the tag is not added, does nothing.
Parameters:
-
name
StringTag name
removeTagContainer
()
Detaches the TagContainer. The instance is no more queryable through the container.
setTagContainer
-
container
Sets the tag container for the instance. If tags are added already, they will appear in the new container. If the instance already has a tagContainer, it will be removed first.
Parameters:
-
container
TagContainerThe container
Events
any
Emitted when any event is emitted. The parameters are the event and the payload.