Moscrif API Docs for: 2012q3
Show:

SceneTransition Class

Extends BaseClass
include "lib://game2d/base/sceneTransition.ms";
Library: game2d

Scene transition base class defines common features of game transitions. This class is used also to extend class defines custom scene transition.

Example:

// create custom transition
class OwnTransition : SceneTransition
{
    function init()
    {
        super.init();
        this._scale = 0;
    }

    //  public fuctions
    function draw(canvas)
    {
        super.draw(canvas);
        // draw initial scene
        if (this._sceneFrom) {
            canvas.save();
            this._sceneFrom.draw(canvas);
            canvas.restore();
        }
        // draw end scene
        if (this._sceneTo) {
            canvas.save();
            // scaled and centered new scene
            canvas.translate(System.width / 2 - (System.width / 2*this._scale).toInteger(), System.height / 2 - (System.height / 2*this._scale).toInteger());
            canvas.scale(this._scale, this._scale);
            this._sceneTo.draw(canvas);
            canvas.restore();
        }
    }

    // sets local variables according to animation state
    function setState(value)
    {
        this._scale = value * 1.0;
        super.setState(value);
    }
    // 
}

Methods

_setDefaults

() private

Inherited from BaseClass

Method is setting control's defaults variables set from current theme.

_setOptions

() private

Inherited from BaseClass

Method is setting control's option variables. Options is present at the contstuct of the object after defaults are applied.

_setProperty

() private

Inherited from BaseClass

Method is parsing options and set properties to the control. Options is a JSON object.

_start

() private

Start transition

afterInit

() protected

Inherited from BaseClass

Method is executed after inititialization of this object

beforeInit

() protected

Inherited from BaseClass

Method is executed before inititialiation of this object

draw

(
  • canvas
)
protected

This method should be overwritten in extended classes to draw scenes with required effect (f.e.: scale scenes, move scenes, fade out scenens etc..).

Parameters:

  • canvas Canvas

    Instance of Canvas class used to draw graphics

Example:

class OwnTransition : SceneTransition
{
    function init()
    {
        super.init();
        this._scale = 0;
    }

    function draw(canvas)
    {
        super.draw(canvas);
        // draw initial scene
        if (this._sceneFrom) {
            canvas.save();
            this._sceneFrom.draw(canvas);
            canvas.restore();
        }
        // draw end scene
        if (this._sceneTo) {
            canvas.save();
            // scaled and centered new scene
            canvas.translate(System.width / 2 - (System.width / 2*this._scale).toInteger(), System.height / 2 - (System.height / 2*this._scale).toInteger());
            canvas.scale(this._scale, this._scale);
            this._sceneTo.draw(canvas);
            canvas.restore();
        }
    }
    ...
}

init

() protected

Inherited from BaseClass

Init object parameters. The init method sets all needed transition properties according to developer requirements or to default values.

push

(
  • fromScene
  • toScene
)

Set scenes, scene from and scene to and start transition

Parameters:

  • fromScene Scene

    start scene

  • toScene Scene

    final scene

push

(
  • fromScene
  • toScene
)

Set scenes, scene from and scene to and start transition

Parameters:

  • fromScene Scene

    start scene

  • toScene Scene

    final scene

setDefaults

() protected

Inherited from BaseClass

Method is setting default class values

setOptions

() protected

Inherited from BaseClass

Method is setting options passed as class parameters

setState

(
  • value
)

This method should be overwritten in extended classes to apply transition effect (f.e.: scale scenes, move scenes, fade out scenens etc..).

Parameters:

  • value Float

    current position in the transition

Example:

// sets local variables according to animation state
function setState(value)
{
    // scale scene
    this._scale = value * 1.0;
    super.setState(value);
}

Properties

defaults

Object

Inherited from BaseClass:

Sets default controls options

duration

Integer

Duration of scene transition in miliseconds

Example:

game.push(scene, new SlideToBottom({
    duration   : 3000,
    transition : Animator.Transition.veryBouncy
}));

initialized

Boolean

Inherited from BaseClass:

options

Object

Inherited from BaseClass:

sceneFrom

Scene

Start scene

sceneTo

Scene

Final scene

transition

Transition

Transition property specifies the behaviour of animator. It defines how transition runs on begin or on the end, if it bounce from the top etc.

Example:

game.push(scene, new SlideToBottom({
    duration   : 3000,
    transition : Animator.Transition.veryBouncy // or Animator.Transition.easyIn or Animator.Transition.easyOut or Animator.Transition.elastic etc.
}));

undefined

Object

Inherited from BaseClass:

Special property (Undefined Property Handler - UPH) executed when property is undefined. It can be that JSON format is in format "key" : "value". Key is an string, so if this is the case methot return "value". As well as k is a regular property of the class it returns getter of this property

Sub-properties:

Events

onComplete

Event to be fired after transition is completed.