Ludicrous Software

Zwoptex and Corona’s New Sprite API

Long time, no blog post, so here’s a quick and easy one to get back into the swing of things. After a season or two away from Corona dev, I’ve recently had reason to return to it to prototype a game. During my time away, Corona’s Sprite API was changed considerably. However, Zwoptex (my sprite sheet generator of choice) has not been updated to output a .lua file that uses the form required by the new API. So here’s the fix for that.

Zwoptex uses template files to generate the actual sprite data files that it outputs for use with Corona, so to get it working with the new API, you need to update that template. The process is pretty straightforward:

  1. In Finder, head to your ‘Applications’ directory
  2. Find Zwoptex.app, right-click on it, and select ‘Show Package Contents’.
  3. In the ‘Contents’ folder, open up ‘Resources’.
  4. In that folder, you’ll find a file called ‘coronasdk.coordinatesformat.txt’.
  5. If you want to be super-safe about things, make a backup copy of that file somewhere.
  6. Open that file in your favourite text editor, and replace it with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module(...)

function getSpriteSheetData()

  local sheet = {
      frames = {
      {% for sprite in spritesAndAliases %}
          {
              name = "{{ sprite.name }}",
              spriteColorRect = { x = {{ sprite.sourceColorRectX }}, y = {{ sprite.sourceColorRectY }}, width = {{ sprite.sourceColorRectWidth }}, height = {{ sprite.sourceColorRectHeight }} },
              textureRect = { x = {{ sprite.textureRectX }}, y = {{ sprite.textureRectY }}, width = {{ sprite.textureRectWidth }}, height = {{ sprite.textureRectHeight }} },
              spriteSourceSize = { width = {{ sprite.sourceSizeWidth }}, height = {{ sprite.sourceSizeHeight }} },
              spriteTrimmed = {% if sprite.isTrimmed %}true{% else %}false{% /if %},
              textureRotated = {% if sprite.isRotated %}true{% else %}false{% /if %}
          },
      {% /for %}
      }
  }

  return sheet
end

Once that’s done, save it, and the next time you use Zwoptex it will spit out sprite data files compatible with the new API. (If you have Zwoptex open while you do this, you may need to restart it for the changes to take; I honestly can’t remember.)