- when the sprites change
A component for using tiles in a sprite map.
This is automatically added to entities which use the components created by
Since these are also used to define tile size, you'll rarely need to use this components methods directly.
public this .sprite(Number x, Number y[, Number w, Number h])
X cell position
Y cell position
Width in cells. Optional.
Height in cells. Optional.
Uses a new location on the sprite map as its sprite. If w or h are ommitted, the width and height are not changed. Values should be in tiles or cells (not pixels).
public this .sprite(String tileName)
the name of a tile specified in the sprite map
Uses a new location on the sprite map as its sprite. The location is retrieved by name from the previously supplied sprite map. An invalid name will be silently ignored.
Crafty.e("2D, DOM, Sprite") .sprite(0, 0, 2, 2); Crafty.e("2D, DOM, flower") .sprite('grass');
The coordinate of the slide within the sprite in the format of [x, y, w, h].
public this .crop(Number x, Number y, Number w, Number h)
Offset x position
Offset y position
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.
Crafty.e("2D, DOM, Sprite") .crop(40, 40, 22, 23);