Skip to main content

Sprite.js

Sprite ⇐ Impacto.GameObjects.Rectangle

This class will draw a Sprite on the canvas.

Kind: global class
Extends: Impacto.GameObjects.Rectangle
Constructors:

new Sprite(x, y, key, [frame], [width], [height])

ParamTypeDefaultDescription
xnumber

The horizontal position of this Sprite in the world.

ynumber

The vertical position of this Sprite in the world.

keystring

The name of the Sprite.

[frame]number0

The frame of the Sprite.

[width]number0

The width of the Sprite.

[height]number0

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

ParamTypeDescription
xnumber

The horizontal position of this Sprite in the world.

Sprite.y

Sets the Y position of the Sprite.

Kind: static property of Sprite

ParamTypeDescription
ynumber

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.

ParamTypeDescription
framenumber

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