API Docs for: 1.0.1

Grape.Scene Class

The root layer in a game. It describes the game FPS and has a default view which can be overridden with initViews.

Methods

add

(
  • instance
)
Grape.GameObject

Adds an instance to the layer and emits it's "add" event.

Parameters:

Returns:

Grape.GameObject:

The added instance

addLayer

(
  • [name]
  • layer
)

Adds a sub-layer to the current layer.

Parameters:

  • [name] String optional

    Layer name

  • layer Grape.Layer

    Sub-layer

addSystem

(
  • [name]
  • system
)

Adds a system to the layer. All events are emitted to all added systems.

Parameters:

  • [name] String optional

    Name

  • system Grape.System

    The system

addView

(
  • name
  • view
)

Adds a view to the layer. A synonym for addSystem.

Parameters:

createResultContainer

() Grape.GameObjectArray

Inherited from Grape.TagContainer but overwritten in js\grape\game\layer.js:153

Overrides the TagContainer's method so getByTag calls produce GameObjectArray results instead of Array.

get

(
  • classes
  • [descendants=false]
)
GameObjectArray

Inherited from Grape.TagContainer but overwritten in js\grape\game\layer.js:184

Gets the instances of one or more class in the current layer (sub-layers not included).

Parameters:

  • classes Class | Array

    Class or classes

  • [descendants=false] Boolean optional

    Get the descendants of that class or just instances of the class itself

Returns:

GameObjectArray:

Instances

getByTag

() Grape.GameObjectArray

Returns the instances with the given tag. Instances are indexed by tags.

Returns:

Grape.GameObjectArray:

Instances with the tag

getGame

() Grape.Game

Returns the current game.

Returns:

Grape.Game:

The game

getScene

() Grape.Scene

Returns the root layer.

Returns:

Grape.Scene:

The root layer

getSystem

(
  • name
)
Grape.System

Returns a system with the given name. Views are also considered as systems.

Parameters:

  • name String

    System name

Returns:

Grape.System:

System

initViews

()

This method is called in the constructor, and adds an initial view to the scene with name 'view'. If you don't want this view, you can override this method and add your own views.

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.Layer

    Name of the layer or the layer itself

removeSystem

(
  • system
)

Removes a system from the layer.

Parameters:

  • system String | Grape.System

    The name of the system or the system itself.

removeView

(
  • name
)

Removes a view from the layer. An alias for removeSystem.

Parameters:

  • name String | Grape.View

    View 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.

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.