Grape.Layer Class
A layer contains instances, systems, and other layers. When any event is emitted to the layer, it is emitted to the systems and layers of the layer too. When you want to subscribe to the layer events with a GameObject (which is added to the layer) you can use the gameObject.onGlobal() function or the global-event keyword.
Constructor
Grape.Layer
-
opts
Parameters:
-
opts
ObjectInitial properties
Item Index
Methods
Methods
add
-
instance
Adds an instance to the layer and emits it's "add" event.
Parameters:
-
instance
Grape.GameObjectInstance
Returns:
The added instance
addLayer
-
[name]
-
layer
Adds a sub-layer to the current layer.
Parameters:
-
[name]
String optionalLayer name
-
layer
Grape.LayerSub-layer
addSystem
-
[name]
-
system
Adds a system to the layer. All events are emitted to all added systems.
Parameters:
-
[name]
String optionalName
-
system
Grape.SystemThe system
addView
-
name
-
view
Adds a view to the layer. A synonym for addSystem.
Parameters:
-
name
StringView name
-
view
Grape.ViewThe view
createResultContainer
()
Grape.GameObjectArray
Overrides the TagContainer's method so getByTag calls produce GameObjectArray results instead of Array.
Returns:
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.
get
-
classes
-
[descendants=false]
Gets the instances of one or more class in the current layer (sub-layers not included).
Parameters:
-
classes
Class | ArrayClass or classes
-
[descendants=false]
Boolean optionalGet the descendants of that class or just instances of the class itself
Returns:
Instances
getByTag
()
Grape.GameObjectArray
Returns the instances with the given tag. Instances are indexed by tags.
Returns:
Instances with the tag
getSystem
-
name
Returns a system with the given name. Views are also considered as systems.
Parameters:
-
name
StringSystem name
Returns:
System
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
remove
-
instance
Removes an instance from the layer and emits it's "remove" event.
Parameters:
-
instance
Object
removeLayer
-
name
Removes a layer.
Parameters:
-
name
String | Grape.LayerName of the layer or the layer itself
removeSystem
-
system
Removes a system from the layer.
Parameters:
-
system
String | Grape.SystemThe name of the system or the system itself.
removeView
-
name
Removes a view from the layer. An alias for removeSystem.
Parameters:
-
name
String | Grape.ViewView name or the view itself
Events
add (instance)
This event is emitted to the instance when it is added to the layer. The parameter is the layer.
any
Emitted when any event is emitted. The parameters are the event and the payload.
remove (instance)
Emitted to the instance when it is removed from the layer.
start (system)
Emitted to a system when it is added to a running layer or when the layer is started with a system added before.
stop (system)
Emitted to a system when it is removed from the running layer or when the layer is stopped.