New formats for SpriteSheets

4 years ago

There has been some new features added to SpriteSheet functionality. In addition to the Zwoptex Flash format LimeJS now also supports the newer Zwoptex (cocos2d) format and JSON format present in TexturePacker. While you could use trimming before you now can pack your files even more by using rotation switching.

We have put a parser logic for each format in the special object that needs to be included with goog.require() and passed in to the SpriteSheet constructor as a third parameter. All currently supported parser objects are:

  • lime.parser.ZWOPTEX - Original Zwoptex format, also known as Zwoptex Flash format or cocos2d-0.99.4
  • lime.parser.ZWOPTEX2 - New Zwoptex format, also known as Zwoptex Generic or cocos2d
  • lime.parser.JSON - JSON format that can be exported from TexturePacker

So your new code may look something like this:


var ss = new lime.SpriteSheet('mysheet.png',lime.ASSETS.mysheet.json,lime.parser.JSON);

Note that previous logic that meant that initializing SpriteSheet with only two parameters is still supported but marked deprecated. It is safest to always pass the third parameter. Maybe in the future we will make JSON format default as it is more JavaScript friendly than XML Zwoptex formats.

If you use the JSON coordinate format make sure you name your file with .json extension before you make it an asset with the gensoy command. This way the program knows to include the file as raw data instead of escaping it into strings that is required for XML formats. Otherwise everything is the same as described in previous post.

To use the new rotation features you don’t have to do anything in the code. Only select “allow rotation” in the program you use for generating the sheet. Everything else is done automatically.

If you think any more formats would be useful for LimeJS let us know in the comments.