Skip to main content

GameObject2D.js

GameObject2D

The base class for a game objects. Probably you don't need to use this class directly. Use this class to extend your own game objects.

Kind: global class
Constructors:

new GameObject2D(x, y, [fillColor], [strokeColor])

ParamTypeDefaultDescription
xnumber

The horizontal position of this Object in the world.

ynumber

The vertical position of this Object in the world.

[fillColor]number | string0xffffff

The color the Object will be filled with, i.e. 0xff0000 for red.

[strokeColor]number | string0x000000

The color of the border of the Object, i.e. 0x00ff00 for green.

Example

class MyGameObject extends Impacto.GameObject.GameObject2D {
constructor(x, y, fillColor, strokeColor, ...args) {
super(x, y, fillColor, strokeColor);
}
}

GameObject2D.setName(name) ⇒ GameObject2D

Set the game object's name.

Kind: static method of GameObject2D

ParamTypeDescription
namestring

The name of the game object.

Example

obj.setName("My Game Object");

GameObject2D.setX(x) ⇒ GameObject2D

Set the horizontal position of the game object in the world based on the origin.

Kind: static method of GameObject2D

ParamTypeDescription
xnumber

The horizontal position of the game object in the world.

Example

obj.setX(100);

GameObject2D.setY(y) ⇒ GameObject2D

Set the vertical position of the game object in the world based on the origin.

Kind: static method of GameObject2D

ParamTypeDescription
ynumber

The vertical position of the game object in the world.

Example

obj.setY(100);

GameObject2D.setZ(z) ⇒ GameObject2D

Set the Z position of the game object in the world based on the origin.

Kind: static method of GameObject2D

ParamTypeDescription
znumber

The Z position of the game object in the world.

Example

obj.setZ(100);

GameObject2D.getPosition() ⇒ Object

Returns the position of the object's in the world relative on the object origin.

Kind: static method of GameObject2D
Returns: Object -

{x:number, y:number, z:number} - The position of the object in the world.


Example

obj.getPosition();

GameObject2D.getRealPosition() ⇒ Object

Returns the real position of the object's in the world. (Not relative on the object origin)

Kind: static method of GameObject2D
Returns: Object -

{x:number, y:number, z:number} - The real position of the object in the world.


Example

obj.getRealPosition();

GameObject2D.setPosition(x, y, z) ⇒ GameObject2D

Set the position of the game object in the world.

Kind: static method of GameObject2D

ParamTypeDescription
xnumber

The horizontal position of the game object in the world.

ynumber

The vertical position of the game object in the world.

znumber

The Z position of the game object in the world.

Example

obj.setPosition(100, 100, 100);

GameObject2D.setRandomPosition() ⇒ GameObject2D

Set a random position of the game object in the world.

Kind: static method of GameObject2D
Example

obj.setRandomPosition();

GameObject2D.setRotation(rotation) ⇒ GameObject2D

Set the rotation of the game object in the world based in radians.

Kind: static method of GameObject2D

ParamTypeDescription
rotationnumber

The rotation of the game object in the world in radians.

Example

obj.setRotation(1.5);

GameObject2D.setAngle(angle) ⇒ GameObject2D

Set the angle of the game object in the world based in degrees.

Kind: static method of GameObject2D

ParamTypeDescription
anglenumber

The angle of the game object in the world in degrees.

Example

obj.setAngle(90);

GameObject2D.setScaleX(scaleX) ⇒ GameObject2D

Set the horizontal scale of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
scaleXnumber

The horizontal scale of the game object.

Example

obj.setScaleX(2);

GameObject2D.setScaleY(scaleY) ⇒ GameObject2D

Set the vertical scale of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
scaleYnumber

The vertical scale of the game object.

Example

obj.setScaleY(2);

GameObject2D.setScale(scale) ⇒ GameObject2D

Set the horizontal and vertical scale of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
scalenumber

The scale of the game object.

Example

obj.setScale(2);

GameObject2D.setOriginX(originX) ⇒ GameObject2D

Set the horizontal origin point of the game object. The origin point is between 0 and 1.

Kind: static method of GameObject2D

ParamTypeDescription
originXnumber

The horizontal origin point of the game object.

Example

obj.setOriginX(0.5);

GameObject2D.setOriginY(originY) ⇒ GameObject2D

Set the vertical origin point of the game object. The origin point is between 0 and 1.

Kind: static method of GameObject2D

ParamTypeDescription
originYnumber

The vertical origin point of the game object.

Example

obj.setOriginY(0.5);

GameObject2D.setOrigin(origin) ⇒ GameObject2D

Set the horizontal and vertical origin point of the game object. The origin point is between 0 and 1.

Kind: static method of GameObject2D

ParamTypeDescription
originnumber

The origin point of the game object.

Example

obj.setOrigin(0.5);

GameObject2D.setFillColor(color) ⇒ GameObject2D

Set the fill color of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
colorstring

The fill color of the game object.

Example

obj.setFillColor("#FF0000");

GameObject2D.setStrokeColor(color) ⇒ GameObject2D

Set the stroke/border color of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
colorstring

The stroke color of the game object.

Example

obj.setStrokeColor("#FF0000");

GameObject2D.setStrokeWidth(width) ⇒ GameObject2D

Set the stroke/border width of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
widthnumber

The stroke width of the game object.

Example

obj.setStrokeWidth(2);

GameObject2D.setVisible(visible) ⇒ GameObject2D

Set the visibility of the game object.

Kind: static method of GameObject2D

ParamTypeDescription
visibleboolean

The visibility of the game object.

Example

obj.setVisible(false);