Ludicrous Software

Using SWFSheet With Corona

Keith Peters has released a new AIR app called SWFSheet, which is designed to generate sprite sheets or png sequences from a SWF file. If you’ve read the Porting Flash to Corona post, one of the things mentioned is using Flash for creating animation sequences and then exporting a sequence of png images for use in Corona.

This works pretty well, but one of the limitations of this approach is that you’re limited to using pretty straightforward timeline animations. If you want to use some pretty particle effects library in ActionScript to create your explosion animation, then getting that from Flash into Corona is a bit of a headache. The great advantage of SWFSheet is that it takes your compiled SWF and generates the image file(s) from that. So, you can produce your animation in Flash (or Flash Builder, or FlashDevelop, FDT, etc., etc.) however you want. As long as you output a SWF file at some point, you can bring that SWF into SWFSheet and take it from there into Corona.

You have a few different approaches when using SWFSheet:

1. sprite.newSpriteSheet()

In this method, import the swf, generate a sprite sheet using SWFSheet, and then create your sprite using sprite.newSpriteSheet(). This is the simplest approach. The downside of this approach is that if, in the future, you modify your sprite to be a different size (e.g. 60 x 60 instead of 50 x 50), you need to go back into your Lua code to modify your newSpriteSheet() call.

2. sprite.newSpriteSheetFromData()

SWFSheet also gives you the option to generate a Lua module that contains a table of sprite data, so you can generate your sprite using sprite.newSpriteSheetFromData(). This approach would be similar to what you’d do if you’re using Zwoptex to generate a sprite data table. The advantage of this approach over approach #1 is that when you create the sprite sheet in SWFSheet, you need to specify the frame width and height. Since you’ve done that already, you can generate the sprite metadata and avoid having to do that again in your Lua code. If your sprite size changes down the road, you can just generate new sprite metadata from within SWFSheet and not have to worry about going back in and changing your code.

3. Export a png sequence

If you have a copy of Zwoptex, then this is the approach I’d recommend. While both Zwoptex and SWFSheet will generate the sprite metadata, Zwoptex gives you more options, specifically the ability to clip transparent pixels, rotate sprite frames, and pack the images more efficiently in the sheet. You can also import any arbitrary set of images into Zwoptex, so you can have a sprite sheet that is used to generate different sprites.┬áIn this approach, you’d use SWFSheet to generate a png sequence, and then import those into Zwoptex, or whatever other program you’d be using the create your sprite sheet.

Whether you’re porting apps from Flash to Corona, or starting from scratch and using Flash as part of your workflow to create animations/effects, SWFSheet is a huge timesaver, and you’ll definitely find it a great addition to your toolset.