Moscrif API Docs for: 2012q3
Show:

GameObject Class

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

GameObject is a base class for all objects used in games. It implements object's base properties like position, width, height etc...

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.

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

Method to defines what is done to redraw object This method can be overwrite to draw something onto object.

Parameters:

  • canvas Canvas

    Current game canvas

Example:

function draw(canvas)
{
    canvas.clear(0xffaabbcc);

    super.draw(canvas);
}

init

() protected

Inherited from BaseClass

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
)
Boolean protected

Check if some object lies within this object.

Parameters:

  • obj GameObject

    Object which position may be checked

Returns:

Boolean: true if passed object intersects this object

intersectsPoint

(
  • x
  • y
)
Boolean protected

Check if x and y coordinates lies inside the object

Parameters:

Returns:

Boolean: True if x and y coordinates lies inside the object

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

Inherited from BaseClass

Method is setting default class values

setOptions

() protected

Inherited from BaseClass

Method is setting options passed as class parameters

setPos

(
  • args
)
chainable

Move object onto new position, given by two parameters (x and y coordinnates), on or position of another object.

Parameters:

  • args Integer | Object multiple

    Two 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.

angle

Float

Current body rotation angle in radians.

defaults

Object

Inherited from BaseClass:

Sets default controls options

height

Integer

Height of the object in pixels.

initialized

Boolean

Inherited from BaseClass:

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

Inherited from BaseClass:

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

scaledWidth

Integer

Scaled width of this object. Scaled width is GameObject.width * GameObject.scale

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:

visible

Boolean

The visible property specifies whether or not an element is visible. Default is set to visible true.

width

Integer

Width of the object in pixels.

x

Integer

X - coordinates of object's centre

Example:

object.x = 100; //pixels

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.