Hello everyone, it's been a while. I've been working on a tool for packing textures and sprite batching. Here is the repo:
https://github.com/ricanteja/MoonySpriteBatch.
How To Use
The library is made up of just 2 headers (Log.h is a bonus). Those are SpriteBatch.h and TextureAtlas.h. These files know everything about loading texture atlases created by the Texture Packer and how to draw sprites.
Texture Packer
Once built you can drop the Texture Packer tool in any directory you want but it is most useful when usd from the commandline. When you run it without any args by default it will sniff around it's current directory for any images to pack. Texture pack files are named after the folder they were created in and texture pack images begin with ta_[NUMBER][FOLDER], for instance: ta_0myimages.png.
Here are the options you can pass to the tool:
-h : Prints a help message with the list of options
-b : Tells the tool not to produce seperate atlas image files but rather compress the raw color data and pack everything into the .mtpf texture pack file
-f [FOLDER] : Designate a folder you specifically want the tool to work in
-r : Recursivley search through all directories under the starting directory. This can be used together with the -f flag
-d [COUNT]: Produce [COUNT] # of debug textures.
-v : Outputs more messages.
Example
The moony::TextureManager class is in charge of loading your texture atlases you made with the tool. You should only need one instance of this object since it can load multiple texture atlases. You can search for the exact texture you want to assign to your sprite by searching by it's original name.
moony::TextureManager textureman;
textureman.loadFromFile("pack.mtpf");
moony::Sprite sprite(textureman.findSubTexture("happytree.png"));
To draw a sprie you need a moony::RenderManager class. It works fairly similar to SFML's own Drawable class (mostly because it inherits from it). Again you should really only need one instance of this class.
moony::RenderManager renderman;
...
window.clear(sf::Color::Black);
renderman.clear();
renderman.draw(sprite);
renderman.batch();
window.draw(renderman);
window.display();
The project has an additional dependency, Zlib, aside from SFML ofcourse. I'm not really good with CMake just yet but I wanted to share it. Maybe someone can use it, learn from it or someone can tell me what I can change and I can learn too.
Everyone loves pictures. Testing that layers indeed work. I didn't upload with the tons of images because it would have been annoying to see all that stuff spinning and doing stuff. But it works so yay!
Here is a picture of what the debug output of the Texture Packer looks like.