API Docs for: 1.0.1

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

()

Methods

addTag

(
  • name
)
Boolean

Adds a tag to a taggable object.

Parameters:

  • name String

    Tag name

Returns:

Boolean:

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 String

    Event

  • payload

    An object passed as parameter to all event listeners.

getGame

() Grape.Game | Null

Gets the current game instance through the current layer.

Returns:

Grape.Game | Null:

The current game, or null, if the lookup fails.

getLayer

() Grape.Layer

Returns the layer the instance is added to.

Returns:

Grape.Layer:

The layer

getScene

() Grape.Scene | Null

Gets the root layer.

Returns:

Grape.Scene | Null:

The root layer, or null, if the lookup fails.

hasTag

(
  • name
)
Boolean

Checks if a tag is added or not.

Parameters:

  • name String

    Tag name

Returns:

Boolean:

true, if the instance has the tag

off

(
  • event
  • listener
)

Unsubscribes from an event.

Parameters:

  • event String

    Event

  • listener Function

    Event listener

on

(
  • event
  • listener
)

Subscribes to an event. The event handler will be called with this instance as context.

Parameters:

  • event String

    The event to subscribe

  • listener Function

    Event 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 String

    Event

  • handler Function

    Event 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 String

    Tag 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 TagContainer

    The container

Events

any

Emitted when any event is emitted. The parameters are the event and the payload.