Moscrif API Docs for: 2012q3
Show:

Scene Class

include "lib://game2d/scene.ms";
Library: game2d

Game scene, object to define a scene what can consist with layers, sprites or buttons.

Example:

class Area : Scene
{
    function init()
    {
        super.init();
        ...
    }

    function draw(canvas)
    {
        super.draw(canvas);
        ...
    }

    function pointerPressed(x, y)
    {
        super.pointerPressed(x, y);
        ...
    }

    function pointerReleased(x,y)
    {
        super.pointerReleased(x,y);
        ....
    }
}

Methods

add

(
  • obj
)
chainable

Add object to the scene

Parameters:

Example:

var sprite = new Sprite({image: fileName});
this.add(sprite);

beforeInit

() protected

Method is executed before inititialiation of the scene object. An empty array of childs is created.

detach

(
  • obj
)
chainable

Detach object from the scene

Parameters:

draw

(
  • canvas
)
protected

Draw event, fire draw methods to all stored objects. This method can be overwrite to draw something onto scene. However it is important to call super.draw(canvas) in overwriten method.

Parameters:

  • canvas Canvas

    Current scene canvas

Example:

function draw(canvas)
{
    canvas.drawRect(0, 0, System.width, System.height, this._bg);
    super.draw(canvas);
}

enter

() protected

Method what execute enter handler if defined.

exit

() protected

Method what execute exit handler if defined

findChild

(
  • name
)

Find child in the scene acording to it name.

Parameters:

  • name String

    name of the object

Returns:

Child or null

Example:

var sprite = this.addPolygonBody(..);
sprite.name = "car";
this.add(sprite);
this.findChild("car").applyAngularImpulse(10);

findControl

(
  • name
)

Find control (button) in the scene acording to it name.

Parameters:

  • name String

    name of the object

Returns:

Control or null

findObject

(
  • name
)

Find object (sprite) in the scene acording to it name.

Parameters:

  • name String

    name of the object

Returns:

Object or null

Example:

var sprite = this.addPolygonBody(..);
sprite.name = "car";
this.add(sprite);
this.findObject("car").applyAngularImpulse(10);

keyPressed

(
  • key
)
protected

Event fired, when user press the key. This method can be overwrite to manage key events. However it is important to call super.keyPressed(key) in overwriten method.

Parameters:

  • key Symbol

    the pressed key

Example:

function keyPressed(key)
{
    super.keyPressed(key);
    if (key == #back)
        Game.instance.pop();
    ...
}

keyReleased

(
  • key
)
protected

Event fired, when user releases the keyy. This method can be overwrite to manage key events. However it is important to call super.keyReleased(key) in overwriten method.

Parameters:

  • key Symbol

    the pressed key

Example:

function keyReleased(key)
{
    super.keyReleased(key);
    if (key == #back)
        Game.instance.pop();
    ...
}

pointerDragged

(
  • x
  • y
)
protected

Event fired, when pointer is dragged. This method can be overwrite to manage pointer dragged event. However, it is important to call super.pointerDragged(x, y) in overwriten method.

Parameters:

pointerPressed

(
  • x
  • y
)
protected

Event fired, when user tap the screen. This method can be overwrite to manage pointer pressed event. However it is important to call super.pointerPressed(x, y) in overwriten method.

Parameters:

Example:

function pointerPressed(x, y)
{
    super.pointerPressed(x, y);

    ...
}

pointerReleased

(
  • x
  • y
)
protected

Event fired, when pointer is released. This method can be overwrite to manage pointer released event. However, it is important to call super.pointerReleased(x, y) in overwriten method.

Parameters:

Example:

function pointerReleased(x, y)
{
    super.pointerReleased(x, y);
    ...
}

process

() protected

Process event, fire process event to all stored objects.

Properties

childs

Array

Access to array of all scene's childs (objects and controls together).

controls

Array

Access to array of scene's controls. This array contains object of GameControl only.

objects

Array

Access to array of scene's objects. This array contains object of GameObject only.

undefined

Object

This property handler is called to deal with undefined properties. (Undefined Property Handler)

Example:

var scene = new Scene({});
scene.add(new Sprite({name:"sprite1"});
var ref = scene.sprite1; // sprite1 is not property of Scene. Thanks to UPH of Scene, Scene class will find it's child by name.

Sub-properties:

  • k String

    Name of undefined property

  • v Object

    Value of undefined property.

Events

onEnter

Event fired on enter to the scene

onExit

Event fired on exit to the scene