Sprite.js
Sprite ⇐ Impacto.GameObjects.Rectangle
This class will draw a Sprite on the canvas.
Kind: global class
Extends: Impacto.GameObjects.Rectangle
Constructors:
- Sprite ⇐
Impacto.GameObjects.Rectangle
- new Sprite(x, y, key, [frame], [width], [height])
- .x
- .y
- .x ⇒
number
- .y ⇒
number
- .setFrame(frame) ⇒
Sprite
- .getNumFramesByWidth() ⇒
number
new Sprite(x, y, key, [frame], [width], [height])
Param | Type | Default | Description |
---|---|---|---|
x | number | The horizontal position of this Sprite in the world. | |
y | number | The vertical position of this Sprite in the world. | |
key | string | The name of the Sprite. | |
[frame] | number | 0 | The frame of the Sprite. |
[width] | number | 0 | The width of the Sprite. |
[height] | number | 0 | The height of the Sprite. |
Example
const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite", 0, 32, 32);
Sprite.x
Sets the X position of the Sprite.
Kind: static property of Sprite
Param | Type | Description |
---|---|---|
x | number | The horizontal position of this Sprite in the world. |
Sprite.y
Sets the Y position of the Sprite.
Kind: static property of Sprite
Param | Type | Description |
---|---|---|
y | number | The vertical position of this Sprite in the world. |
Sprite.x ⇒ number
Kind: static property of Sprite
Returns: number
-
The horizontal position of this Sprite in the world relative to the origin.
Sprite.y ⇒ number
Kind: static property of Sprite
Returns: number
-
The vertical position of this Sprite in the world relative to the origin.
Sprite.setFrame(frame) ⇒ Sprite
Change the frame of this Sprite.
Kind: static method of Sprite
Returns: Sprite
-
The Sprite itself.
Param | Type | Description |
---|---|---|
frame | number | The frame of the Sprite. |
Example
new Impacto.GameObjects.Sprite(400, 300, "MySprite", 0, 32, 32).setFrame(1);
Sprite.getNumFramesByWidth() ⇒ number
Returns the number of frames of this Sprite based on the width.
Kind: static method of Sprite
Returns: number
-
The number of frames by width.
Example
new Impacto.GameObjects.Sprite(400, 300, "MySprite", 0, 32, 32).getNumFramesByWidth(); // 8