Layer Class
Layer, object to define a layer which can consist with sprites or buttons. It can be inclded into scene to group similar objects.
Example:
class ColoringLayer : Layer
{
function init()
{
super.init();
}
function draw(canvas)
{
canvas.clear(0xffffffff);
...
super.draw(canvas);
}
}
...
var layer = new ColoringLayer({z : 2, width : System.width, height : System.height})
scene.add(layer);
Item Index
Methods
Methods
add
obj
Add GameControl or GameObject (Button or Sprite) to the layer.
Parameters:
-
objGameControl | SpriteThe object to be stored in layer
Example:
class Menu : Layer
{
function init()
{
super.init();
var close = Bitmap.fromFile("app://ico-close.png")
this._closeBtn = new ImageButton({image : close, x : System.width - close.width, y : close.height, onClick : function(){game.quit();}})
this.add(this._closeBtn);
...
}
...
}
beforeInit
() protected
Init object parameters.
detach
obj
Remove object from the layer.
Parameters:
-
objGameControl | SpriteThe object to be stored in layer
draw
canvas
Draws this layer and all added objects. This method can be overwrite to draw something onto layer. However it is important to call super.draw(canvas) in overwriten method.
Parameters:
-
canvasCanvasThe canvas.
Example:
function draw(canvas)
{
canvas.drawRect(0, 0, System.width, System.height, this._bg);
super.draw(canvas);
}
findChild
name
Find child in the layer acording to it name.
Parameters:
-
nameStringName of the object
Returns:
Example:
var sprite = this.addPolygonBody(..);
sprite.name = "car";
this.add(sprite);
this.findChild("car")....; // car sprite
findControl
name
Find control (button) in the layer acording to it name.
Parameters:
-
nameStringof the object
Returns:
findObject
String
Find object (sprite) in the layer acording to its name.
Parameters:
-
StringObjectname of the object
Returns:
Example:
var sprite = this.addPolygonBody(..);
sprite.name = "car";
this.add(sprite);
this.findObject("car")....; // car sprite
pointerDragged
xy
This methos is called, when pointer is dragged.
pointerPressed
xy
This method is called when user tap the screen. It can be overwritten to manage pointer pressed event. However, it is important to call super.pointerPressed(x, y) in overwriten method.
Example:
function pointerPressed(x, y)
{
super.pointerPressed(x, y);
if (x<System.width / 2)
console<<"user tap on the left half of screen\n"
}
pointerReleased
xy
This methos is called, 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.
Example:
function pointerReleased(x, y)
{
super.pointerReleased(x, y);
if (x<System.width / 2)
console<<"user tap on the left half of screen\n"
...
}
process
() protected
Process event, fire process event to all stored objects
Properties
childs
Array
Access to array of all layers's childs (objects and controls together).
controls
Array
Access to array of all layers's controls (f.e.: buttons).
objects
Array
Access to array of all layers's objects (f.e.: sprites).
undefined
Object
This property handler is called to deal with undefined properties. (Undefined Property Handler)
Example:
var layer = new Layer({});
layer.add(new Sprite({name:"sprite1"});
var ref = layer.sprite1; // sprite1 is not property of Layer. Thanks to UPH of Layer, Layer class will find it's child by name.
Sub-properties:
-
kStringName of undefined property
-
vObjectValue of undefined property.
