Skip to content

How to use Texture Atlas with TexturePacker

Olivier Biot edited this page Sep 26, 2015 · 41 revisions

[WIP]

featurecarousel_texturepacker

Using a texture Atlas will generally allow you to :

  • save memory, by packing all your sprites into a single texture
  • increase your framerate, by optimising the GPU usage
  • make your game starts faster, by loading a single texture

In this tutorial we are gonna to see how to :

  • use TexturePacker to create a texture atlas
  • import the generated texture into a melonJS project
  • add a static renderable sprite
  • add a renderable animation

create a Texture atlas

To create a new texture atlas, simply start TexturePacker and select the generic JSON (Array) framework : create new project

Then drag & drop the directory containing your sprite images to the Sprites area of TexturePacker. TexturePacker will automatically load and lay out all image files. For this example we use the assets from the texture packer example here (see the cityscene folder).

imported files

After that use the file selection button to enter a Data file, name it cityscene.json and place it in the [img] folder (to follow the melonJS boilerplate structure), and do the same for the texture file by choosing cityscene.png in Texture file's file selector (also place it in the same folder).

Recommended settings :

  • use "Power of Two" size for the texture, especially if you do plan to use the webGL renderer, to optimize the use of GPU memory
  • we recommend not to use texture rotation when possible (although this will increase the final texture size), as it forces melonJS to apply a default rotation angle when drawing sprites and, based on how many sprites are to be displayed, can impact performance.

Finally press the [Publish sprite sheet] to create the sprite sheet, and we are done in TexturePacker !

melonJS boilerplate

add the static background

add the cap guy animation

source code

https://github.com/melonjs/melonJS/tree/master/examples/texturepacker

Clone this wiki locally