Getting started with TexturePacker and CoronaSDK image sheets

Andreas Löw
Getting started with TexturePacker and CoronaSDK image sheets
Last update: More than 3 months ago

What you are going to learn:

  • Introduction of the new CoronaSDK ImageSheet API
  • Using it with TexturePacker

Full source code to this example project is available on GitHub

This is a short tutorial how to use TexturePacker with the new ImageSheet API from Corona SDK. The API is not yet documented and might still be unstable...

You need one of the current nightly builds of CoronaSDK which includes the new API.

To use the new API with TexturePacker you need the current 3.0.0 build which is currently available as beta version from the download section of this page.

Overview over the important files

  • spritesheet.tps - TexturePacker file to create the sprite sheets

  • spritesheet.lua - Sprite definition file ("old" format)

  • spritesheet.png - Png image containing the sprite data

  • main.lua - The code driving the example

The complete code

First load the image sheet information file created with TexturePacker into memory

local sheetInfo = require("spritesheet")

Load the created image file:

local myImageSheet = graphics.newImageSheet( "spritesheet.png", sheetInfo:getSheet() )

To place a file create a new image Object with newImage, using the image sheet loaded before. You can select individual sprites by their name using getFrameIndex:

local myImage1 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("drink"))
local myImage2 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("hamburger"))