
Sprite class.
Kind: global class
TextureAssetBaseVector2 | Vector3Vector2 | Vector3RectangleNumberVector2Vector2Color | Array.<Color>BooleanBooleanSpriteSpriteSpriteCreate the sprite object.
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Sprite texture. |
| [sourceRectangle] | Rectangle |
Optional source rectangle. |
TextureAssetBaseSprite’s texture.
Kind: instance property of Sprite
Vector2 | Vector3Sprite position. If Vector3 is provided, the z value will be passed to vertices position in shader code.
Kind: instance property of Sprite
Vector2 | Vector3Sprite size. If Vector3 is provided, the z value will be passed to the bottom vertices position in shader code, as position.z + size.z.
Kind: instance property of Sprite
RectangleSprite source rectangle in texture. Null will take entire texture.
Kind: instance property of Sprite
NumberSprite rotation in radians.
Kind: instance property of Sprite
Vector2Sprite origin point.
Kind: instance property of Sprite
Vector2Skew the sprite corners on X and Y axis, around the origin point.
Kind: instance property of Sprite
Color | Array.<Color>Sprite color. If array is set, will assign each color to different vertex, starting from top-left.
Kind: instance property of Sprite
BooleanCheck if this sprite is flipped around X axis. This is just a sugarcoat that returns if size.x < 0.
Kind: instance property of Sprite
Returns: Boolean - If sprite is flipped on X axis.
Flip sprite around X axis. This is just a sugarcoat that set size.x to negative or positive value, without changing its scale.
Kind: instance property of Sprite
| Param | Type | Description |
|---|---|---|
| flip | Boolean |
Should we flip the sprite around X axis. If undefined, will take the negative of flipX current value, ie will toggle flipping. |
BooleanCheck if this sprite is flipped around y axis. This is just a sugarcoat that returns if size.y < 0.
Kind: instance property of Sprite
Returns: Boolean - If sprite is flipped on Y axis.
Flip sprite around Y axis. This is just a sugarcoat that set size.y to negative or positive value, without changing its scale.
Kind: instance property of Sprite
| Param | Type | Description |
|---|---|---|
| flip | Boolean |
Should we flip the sprite around Y axis. If undefined, will take the negative of flipY current value, ie will toggle flipping. |
SpriteSet size to source rectangle size.
Kind: instance method of Sprite
Returns: Sprite - this.
SpriteSet size to texture size.
Kind: instance method of Sprite
Returns: Sprite - this.
Set the source Rectangle automatically from spritesheet. This method get sprite index in sheet and how many sprites there are in total, and calculate the desired offset and size in source Rectangle based on it + source image size.
Kind: instance method of Sprite
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to set source rectangle from. |
| index | Vector2 |
Sprite index in spritesheet. |
| spritesCount | Vector2 |
How many sprites there are in spritesheet in total. |
| [margin] | Number |
How many pixels to trim from the tile (default is 0). |
| [setSize] | Boolean |
If true will also set width and height based on source rectangle (default is true). |
SpriteClone this sprite.
Kind: instance method of Sprite
Returns: Sprite - cloned sprite.
SpriteBuild a sprite from params.
Kind: static method of Sprite
Returns: Sprite - New sprite instance.
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Sprite texture. |
| position | Vector2 | Vector3 |
Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute. |
| size | Vector2 | Vector3 | Number |
Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z. |
| sourceRectangle | Rectangle |
Source rectangle, or undefined to use the entire texture. |
| color | Color | Array.<Color> | undefined |
Tint color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate sprite. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
| [skew] | Vector2 |
Skew the drawing corners on X and Y axis, around the origin point. |