GameObject Class
GameObject is a base class for all objects used in games. It implements object's base properties like position, width, height etc...
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.
afterInit
() protected
Method is executed after inititialization of this object
beforeInit
() protected
Method is executed before inititialiation of this object
draw
canvas
Method to defines what is done to redraw object This method can be overwrite to draw something onto object.
Parameters:
-
canvas
CanvasCurrent game canvas
Example:
function draw(canvas)
{
canvas.clear(0xffaabbcc);
super.draw(canvas);
}
init
() protected
Initialise Game object instance. This method should be used as a class constructor in extended classes. However, it is important to call parent's init method (by super.init()) to ensure correct object initialization.
Example:
function init()
{
super.init();
this._name = String.printf("sprite%d", Sprite.instance++);
this._frame = 0;
this._frameWidth = -1;
this._frameHeight = -1;
this._totalFrames = 0;
}
intersectsBounds
obj
Check if some object lies within this object.
Parameters:
-
obj
GameObjectObject which position may be checked
Returns:
intersectsPoint
x
y
Check if x and y coordinates lies inside the object
Returns:
process
() protected
On process method is called every about 25 miliseconds, and is a good place for asynchronous operations. F.e.: it is good place to remove physics elements from physics world, or check changes in source data etc.
setDefaults
() protected
Method is setting default class values
setOptions
() protected
Method is setting options passed as class parameters
setPos
args
Move object onto new position, given by two parameters (x and y coordinnates), on or position of another object.
Parameters:
-
args
Integer | Object multipleTwo integers to place object onto two required coordinates (x and y), or one instance of GameObject class to place object onto same coorinates as GameObject has.
Example:
// place onto required position
character.setPos(300, 150);
// place onto position of another object
var sprite = new Sprite({x: 0, y:0});
character.setPos(sprite);
Properties
anchorY
Integer
AnchorPoint is the point around which all transformations and positioning manipulations take place. It's like a pin in the node where it is "attached" to its parent. This property sets or gets Y-axis value ranged from 0 to GameObject/height of this object.
defaults
Object
Sets default controls options
initialized
Boolean
name
String
Name of the game object. Elements in scene or layer can be axxess also by theirs name.
Example:
var layer = new Layer({});
layer.add(new Sprite({name:"sprite1"});
var ref = layer.sprite1; // sprite1 is not property of Layer. Thanks to UPH (undefined property handler) of Layer, Layer class will find it's child by name.
options
Object
scale
Float
Scale of the game object. The value 1.0 means no scale, value less then 1.0 scales down, vales up to 1.0 scale the object up.
scaledHeight
Integer
Get scaled height of this object. Scaled width is GameObject.height * GameObject.scale
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
visible
Boolean
The visible property specifies whether or not an element is visible. Default is set to visible true.
y
Integer
Y - coordinates of objects's centre
Example:
object.y = System.height / 2; // place object to the center of the screen (vertically)
z
Integer
The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order
Events
onProcess
On process event appears at every about 25 miliseconds, and is a good place for asynchronous operations. F.e.: it is good place to remove physics elements from physics world, or check changes in source data etc.