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:
- GameObject2D
- new GameObject2D(x, y, [fillColor], [strokeColor])
- .setName(name) ⇒
GameObject2D
- .setX(x) ⇒
GameObject2D
- .setY(y) ⇒
GameObject2D
- .setZ(z) ⇒
GameObject2D
- .getPosition() ⇒
Object
- .getRealPosition() ⇒
Object
- .setPosition(x, y, z) ⇒
GameObject2D
- .setRandomPosition() ⇒
GameObject2D
- .setRotation(rotation) ⇒
GameObject2D
- .setAngle(angle) ⇒
GameObject2D
- .setScaleX(scaleX) ⇒
GameObject2D
- .setScaleY(scaleY) ⇒
GameObject2D
- .setScale(scale) ⇒
GameObject2D
- .setOriginX(originX) ⇒
GameObject2D
- .setOriginY(originY) ⇒
GameObject2D
- .setOrigin(origin) ⇒
GameObject2D
- .setFillColor(color) ⇒
GameObject2D
- .setStrokeColor(color) ⇒
GameObject2D
- .setStrokeWidth(width) ⇒
GameObject2D
- .setVisible(visible) ⇒
GameObject2D
new GameObject2D(x, y, [fillColor], [strokeColor])
Param | Type | Default | Description |
---|---|---|---|
x | number | The horizontal position of this Object in the world. | |
y | number | The vertical position of this Object in the world. | |
[fillColor] | number | string | 0xffffff | The color the Object will be filled with, i.e. 0xff0000 for red. |
[strokeColor] | number | string | 0x000000 | 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
Param | Type | Description |
---|---|---|
name | string | 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
Param | Type | Description |
---|---|---|
x | number | 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
Param | Type | Description |
---|---|---|
y | number | 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
Param | Type | Description |
---|---|---|
z | number | 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
Param | Type | Description |
---|---|---|
x | number | The horizontal position of the game object in the world. |
y | number | The vertical position of the game object in the world. |
z | number | 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
Param | Type | Description |
---|---|---|
rotation | number | 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
Param | Type | Description |
---|---|---|
angle | number | 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
Param | Type | Description |
---|---|---|
scaleX | number | 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
Param | Type | Description |
---|---|---|
scaleY | number | 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
Param | Type | Description |
---|---|---|
scale | number | 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
Param | Type | Description |
---|---|---|
originX | number | 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
Param | Type | Description |
---|---|---|
originY | number | 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
Param | Type | Description |
---|---|---|
origin | number | 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
Param | Type | Description |
---|---|---|
color | string | 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
Param | Type | Description |
---|---|---|
color | string | 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
Param | Type | Description |
---|---|---|
width | number | 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
Param | Type | Description |
---|---|---|
visible | boolean | The visibility of the game object. |
Example
obj.setVisible(false);