Sprite
Extends:
The class to use sprite image You can add animations
Example:
const image = loader.get('my-sprite'); // see Loader documentation
const animation = [{ frames: [9, 10, 11, 12], name: 'walk', loop: true }];
let sprite = new Sprite(10, 10, 20, 20, image, animation);
sprite.play('walk');
sprite.render();
Static Method Summary
Static Public Methods | ||
public static |
deserialize(data: Object): Sprite |
Constructor Summary
Public Constructor | ||
public |
constructor(x: number, y: number, tileWidth: number, tileHeight: number, image: Image, animations: Array<Object>, hitbox: Object) |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
image: Image |
|
public |
|
|
public |
|
Method Summary
Public Methods | ||
public |
Play animation |
|
public |
Render the sprite |
|
public |
reset() Reset animation |
|
public |
|
|
public |
|
|
public |
stop() Stop animation |
Inherited Summary
From class EventEmitter | ||
protected |
List of registers |
|
public |
Dispatch event |
|
public |
Listen event |
From class Model | ||
public static |
deserialize(data: Object): Model |
|
public get |
|
|
public set |
|
|
public get |
|
|
public set |
x: * |
|
public get |
|
|
public set |
y: * |
|
public |
|
|
public |
|
|
public |
parent: {} |
|
public |
|
|
public |
|
|
public |
|
|
public |
|
Static Public Methods
public static deserialize(data: Object): Sprite source
Override:
Model#deserializeParams:
Name | Type | Attribute | Description |
data | Object | ||
data.x | number | ||
data.y | number | ||
data.width | number | ||
data.height | number | ||
data.hitbox | Object | ||
data.collision | boolean | ||
data.image | Image | ||
data.animations | Object | ||
data.time | number | ||
data.stopped | boolean | ||
data.frame | Object | ||
data.currentAnimation | number | ||
data.currentFrame | number |
Public Constructors
public constructor(x: number, y: number, tileWidth: number, tileHeight: number, image: Image, animations: Array<Object>, hitbox: Object) source
Override:
Model#constructorParams:
Name | Type | Attribute | Description |
x | number | ||
y | number | ||
tileWidth | number | width tile |
|
tileHeight | number | height tile |
|
image | Image | ||
animations | Array<Object> | list of animations |
|
hitbox | Object |
|
|
hitbox.x | number |
|
|
hitbox.y | number |
|
|
hitbox.width | number |
|
|
hitbox.height | number |
|
Example:
new Sprite(0, 0, 20, 20, image, [{ frames: [9, 10, 11, 12], name: 'walk', loop: true, flip: false }]);
Public Members
public image: Image source
Public Methods
public play(animation: String) source
Play animation
Params:
Name | Type | Attribute | Description |
animation | String |
public render(ctx: RenderingContext, drawer: Drawer) source
Render the sprite
Override:
Model#renderParams:
Name | Type | Attribute | Description |
ctx | RenderingContext |
|
|
drawer | Drawer |
|
public step(dt: number) source
Override:
Model#stepParams:
Name | Type | Attribute | Description |
dt | number | Delta between two frames |