SceneTransition Class
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);
}
//
}
Item Index
Methods
Properties
Events
Methods
_setDefaults
() private
Method is setting control's defaults variables set from current theme.
_setOptions
() private
Method is setting control's option variables. Options is present at the contstuct of the object after defaults are applied.
_setProperty
() private
Method is parsing options and set properties to the control. Options is a JSON object.
_start
() private
Start transition
afterInit
() protected
Method is executed after inititialization of this object
beforeInit
() protected
Method is executed before inititialiation of this object
draw
canvas
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
CanvasInstance 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
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
push
fromScene
toScene
Set scenes, scene from and scene to and start transition
setDefaults
() protected
Method is setting default class values
setOptions
() protected
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
Floatcurrent 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
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
options
Object
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
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:
-
key
String -
value
Object
Events
onComplete
Event to be fired after transition is completed.