UnChaos : Texture packing tool
by Sven Bergström · in iTorque 2D · 11/20/2009 (6:10 pm) · 42 replies
One of the necessities of working with mobile and 2d games in general is using the best possible setup for images and imagemaps. Packing images into sprite sheets can be tedious, and if one change arises its a pain in the ass to redo everything, and readjust all image source rects / spaces again.
Enter UnChaos :

UnChaos takes images from a folder, and packs them using clever algorithms to pack the images as tight as it can get. Not just a configurable tool for saving a packed image - it also saves out a source rects text file and an alpha mask.
Usage
To use the tool, you give it a directory to process (move the images into a folder for conversion). You can see below that my images are all arbitrary sizes and there is no restriction with power of two or square for pvr. Only my end result needs to have a square power of two size. It also supports padding/cell/margining the images as well.

The prefix and suffix options allow easy conversion to code. The output in the text file can be directly variables.

For reference, it is GOOD PRACTICE and an important thing to remember that changing repetitive things is annoying and slow. Use variables to store the values - requiring only one change for all uses of thse sprite!!! This is crucial too :)
A kick ass easy to use, readily packed image for PVR, and for engine use on iPhone.

Currently in your version, t2dStaticSprite fully supports this system.
You can see how there is now only ONE image map, but multiple references to it.
Some other important notes are that now you have control over 2 images , not 100. so unloading / loading levels and clearing memory is simple! As you can see there are massive benefits to working this way. It also means you can use the editor as normal, working on windows etc - and as soon as the level is done and ready for iPhone, its a small optimisation pass that involves copy paste from the output text file.
You may also noticed that i had "hardcoded the values" into the sprites. Instead, using the text file as is :
Some animation info
Animations are normally the same size frames, meaning you can just use the normal CELL image map type, and let TGB offer you frames to use.
Some other interesting uses is packing normal animation sequences into one image, the sizes can be the same to make normal CELL sheets from image sequences.
Download
Some notes :
Windows only (atm, i am porting it to OSX).
Credit Goes to Diorgo Jonkers (Luma Arcade) and uses BGMLib.
http://members.cox.net/scottheiman/bmglib.htm
Disclaimer :
This tool is not an official tool. It is provided as convenience and is most likely not connected to any support relationship. post issues you have in this thread.
Enter UnChaos :

UnChaos takes images from a folder, and packs them using clever algorithms to pack the images as tight as it can get. Not just a configurable tool for saving a packed image - it also saves out a source rects text file and an alpha mask.
Usage
To use the tool, you give it a directory to process (move the images into a folder for conversion). You can see below that my images are all arbitrary sizes and there is no restriction with power of two or square for pvr. Only my end result needs to have a square power of two size. It also supports padding/cell/margining the images as well.

The prefix and suffix options allow easy conversion to code. The output in the text file can be directly variables.

For reference, it is GOOD PRACTICE and an important thing to remember that changing repetitive things is annoying and slow. Use variables to store the values - requiring only one change for all uses of thse sprite!!! This is crucial too :)
The results
A kick ass easy to use, readily packed image for PVR, and for engine use on iPhone.

Using the results in game
Currently in your version, t2dStaticSprite fully supports this system.
new t2dImageMapDatablock(allShipsImageMap) {
imageName = "~/data/images/allShips";
...
new t2dStaticSprite(pShip) {
imageMap = "allShipsImageMap";
frame = "0";
mUseSourceRect = "1";
sourceRect = "0 0 44 18";
...
new t2dStaticSprite(BigBoss) {
imageMap = "allShipsImageMap";
frame = "0";
mUseSourceRect = "1";
sourceRect = "0 18 93 48";You can see how there is now only ONE image map, but multiple references to it.
Some other important notes are that now you have control over 2 images , not 100. so unloading / loading levels and clearing memory is simple! As you can see there are massive benefits to working this way. It also means you can use the editor as normal, working on windows etc - and as soon as the level is done and ready for iPhone, its a small optimisation pass that involves copy paste from the output text file.
function levelCleanup()
{
pShip.delete(); //MUST remove references first, or no memory is freed!
BigBoss.delete();
allShipsImageMap.delete();
}You may also noticed that i had "hardcoded the values" into the sprites. Instead, using the text file as is :
mUseSourceRect = "1";
sourceRect = $SR_BG_GROUND_04;Some animation info
Animations are normally the same size frames, meaning you can just use the normal CELL image map type, and let TGB offer you frames to use.
Some other interesting uses is packing normal animation sequences into one image, the sizes can be the same to make normal CELL sheets from image sequences.
Download
Download
Some notes :
Windows only (atm, i am porting it to OSX).
Credit Goes to Diorgo Jonkers (Luma Arcade) and uses BGMLib.
http://members.cox.net/scottheiman/bmglib.htm
Disclaimer :
This tool is not an official tool. It is provided as convenience and is most likely not connected to any support relationship. post issues you have in this thread.
Associate Sven Bergström
Luma Arcade
0) Post new threads, so people can find the information thats relevant to them :)
1) Yes, it is possible. Here is an example of two images, on the same sprite sheet, using standard cell imagemaps.
new t2dImageMapDatablock(some68xAnim_ImageMap) { imageName = "~/data/images/commonImage"; imageMode = "CELL"; frameCount = "36"; filterMode = "SMOOTH"; filterPad = "0"; preferPerf = "1"; cellRowOrder = "1"; cellOffsetX = "6"; cellOffsetY = "646"; cellStrideX = "80"; cellStrideY = "80"; cellCountX = "12"; cellCountY = "3"; cellWidth = "68"; cellHeight = "68"; preload = "1"; allowUnload = "1"; optimised = "1"; force16bit = "1"; }; new t2dImageMapDatablock(some128xAnim_ImageMap) { imageName = "~/data/images/commonImage"; imageMode = "CELL"; frameCount = "40"; filterMode = "SMOOTH"; filterPad = "0"; preferPerf = "1"; cellRowOrder = "1"; cellOffsetX = "0"; cellOffsetY = "0"; cellStrideX = "0"; cellStrideY = "0"; cellCountX = "8"; cellCountY = "5"; cellWidth = "128"; cellHeight = "128"; preload = "1"; allowUnload = "1"; optimised = "1"; force16bit = "1"; }; };How you use these, is the same as before.
t2dStaticSprite(sprite128) { imageMapName = "some128xAnim"; }; t2dStaticSprite(sprite68) { imageMapName = "some68xAnim"; };Of course, the sprites are an example, The animations use an animation controller datablock but work the same way.
2) A simple function called, worldToScreenSpace (dont think it is part of the engine, i tried searching) will probably do the trick.
For example, here is some psuedo code. World space is simply offset, to make 0,0 the origin if the camera is at 0 0. That make the offset a simple 240, 160 in landscape mode and 160, 240 in portrait. So if you have :
Point2I worldToScreenCoord(Point2I worldPos) { Point2I tmp = worldPos; tmp.mX += 240; tmp.my += 160; return tmp; }Note this is not tested, basically just pseudo code. Also note that this will only work if the camera never moves. As soon as the camera moves, its adjusted by the camera offset in the world etc etc.
Hope this helps.