Sprites
Texture Atlases (Sprite Sheets)
Packed texture atlases created with the tool Free Texture Packer (FTP) are supported and can be loaded with yg.asset.loadTexture().
Tested with Free Texture Packer v0.6.7.
The following FTP settings are required. The rest can be set to users taste.
- Format:
JSON (hash)orJSON (array) - Allow rotation:
No - Allow trim:
No - Padding:
>= 2(recommended)
Accessing Sprites and Sequences
To draw a sprite from a texture atlas, the draw function must know where to find the desired sprite in the texture. The following functions can be used on a yg.gl.Texture to retrieve these coordinate information.
- yg.gl.Texture.getCoords(): get coordinates for a sprite that has been listed in the atlas file (
.json) by it's name. This is always possible, even if the sprite is part of a sequence - yg.gl.Texture.getFrameCoords(): get coordinates from a frame index of a sequence
During texture loading, sequences are detected if the sprite names have indexes at the end, separated with - or _.
Examples:
walking_01-> sequencewalkingdetected, yg.gl.Texture.getFrameCoords() can be usedwalking-01-> sequencewalkingdetected, yg.gl.Texture.getFrameCoords() can be usedwalking01-> no sequence detected, only yg.gl.Texture.getCoords() can be used