I've spent a while getting all this to work - here goes ;)
I got the information about sprite trimming from the latest Corona SDK in the sample code HorseAnimation. You will see in uma.lua that trimming is used by setting the values for sourceX, sourceY, sourceWidth and sourceHeight for the imagesheet.
The code that I posted previously adds these values to the exporter for conorna SDK in TexterPacker.
The steps to get this working are:
- Create a new exporter by opening the TexturePacker package then create a copy of the Corona Exporter folder under Resources/exporters/corona-imagesheet
- Rename the new folder something like corona-trim-imagesheet.
- Rename the corona-imagesheet.lua to corona-trim-imagesheet.lua
- Open corona-trim-imagesheet.lua and replace the frames section with the code I posted previously.
- Open the exporter.xml file in the new folder.
- Change the name element to reference the new name "corona-trim-imagesheet".
- Change the template element to reference the new .lua file "corona-trim-imagesheet.lua"
- Change the supportsTrimming element to "true".
- Launch TexturePacker and you should now have a corona-trim-imagesheet option.
I have used the API and it is stable enough. The main problem you will have is with dynamic image scaling. As Andreas mentioned TexturePacker will always try and pack the images as best as possible. If this results in odd pixels (or more accurately pixels that are not divisible by the scale you want to produce) then the images will jump around slightly due to different offsets.
For now I am not using trimming as I need to use dynamic image scaling. I think some kind of trimming divisor will be needed in TexturePacker to fully support this feature, but seeing as the API is not yet in a Corona stable release I doubt that Andreas will want to commit to adding the functionality ;)
The other problem that you will find is when you are creating multiple resolutions. You should work with the highest resolution first but must make sure that the images are divisible by the other scales you want to use. If they are not then you will find that TexturePacker (rightly so) may move the images around when you change the scale.
The way I make this work is to ensure that all my images at the highest resolution I am going to use are divisible by the other scales I want to use e.g. if I am using scales 1.0 and 2.0 then I just need to make sure that the width/height of my 2.0 images are all even (divisible by 2). When using TexturePacker I use an imagesheet that is 2048x2048 and set padding to 4. I export these images and then change the scale to 0.5 and change padding to 2 then export my 1.0 scale images. You must use the .lua file in Corona that was generated for the 1.0 scale images.
It gets more complicated if you are producing assets for more resolutions. For example if you are going to use 1.0, 1.5 and 2.0 you must make sure the high res images are divisible by 4. This is so that when you set the scale to 0.75 for your 1.5 resolution images there will still be a whole number of pixels for TexturePacker to work with. For scales 1.0, 1.8 and 4.0 you will need your high res images to be divisible by 20!
Hope this helps,
uid: 77943 topic_id: 23739 reply_id: 110636