craftyjs.github.com

Sprite

Events

Change
when the sprites change

Component for using tiles in a sprite map.

Back to top

.sprite

public this .sprite(Number x, Number y, Number w, Number h)

x
X cell position
y
Y cell position
w
Width in cells
h
Height in cells

Uses a new location on the sprite map as its sprite.

Values should be in tiles or cells (not pixels).

Example

Crafty.e("2D, DOM, Sprite")
    .sprite(0, 0, 2, 2);
Back to top

.__coord

The coordinate of the slide within the sprite in the format of [x, y, w, h].

Back to top

.crop

public this .crop(Number x, Number y, Number w, Number h)

x
Offset x position
y
Offset y position
w
New width
h
New height

If the entity needs to be smaller than the tile size, use this method to crop it.

The values should be in pixels rather than tiles.

Example

Crafty.e("2D, DOM, Sprite")
    .crop(40, 40, 22, 23);