This tells this sprite to use the atlas SheetName. As you can see, we’re setting the frames property to use the FlxAtlasFrames we just loaded in our singleton. This function is used instead of the usual loadGraphic you use when loading a single image file.
Public function loadGraphicFromSheet(SheetName:String, ?Single:String) Actually loading an atlas is done like this in the constructor of the singleton: My singleton contains a private map _sheets of type Map which, as you can probably guess, stores all the loaded atlases, along with a name for easy retrieval. You don’t have to do it that way, but I find it useful because a) it makes sure that the atlas is only loaded once and b) it actually makes it easier to load and deal with multiple atlases. To load the atlas, I use a singleton called SheetBox. Then, each entity in the game grabs the frames it needs from the atlas.
This can be separated into two sub-steps: First, we load the atlas into memory. The next step is loading and using the atlas (or “sheet”) we’ve just created. Now plop the texture and xml file somewhere in the assets folder of your game. Also note how they’re not in order, because Free Texture Packer sorts them as it sees fit (which is perfectly fine, as we won’t manually work with this list anyway): Note the numbered pogogirl entries, which are all animation frames of PogoGirl. This file will serve as a “directory” for HaxeFlixel to look up what sprite has been stored where in the atlas texture.įor reference, this is what my export settings look like in Free Texture Packer:Īnd this is a snippet from my exported. The xml file contains a list of all your sprites (using the file names) along with their x- and y-positions within the texture. If you’re using Free Texture Packer, make sure to export the descriptor in xml format. Finally, export that big texture along with a descriptor file.It will then pack them together into one big texture. Point your texture packer to the folder containing all your images.Make sure that files belonging to the same animation are numbered: For example, pogogirl1.png, pogogirl2.png, pogogirl3.png… This means that every frame of every animation of every sprite should be its own image file (preferably. Export all your sprites as single images.But broadly speaking, this is what you want to do: I’m not gonna give you a full tutorial on how to use it, as it’s not that complex. It’s free, flexible and gives me everything I need. There are a bunch of different programs for creating a texture atlas, but I use Free Texture Packer. Packing Texturesīroadly speaking, there are two big steps when using texture atlases: Preparing the texture atlas, and loading it in the game. Note that there are probably better and smarter ways to do it, but this approach works for me. However, it can be a bit confusing figuring out how it all works, so let me explain how I do it! Luckily, HaxeFlixel has a lot of built-in functions to help you out. I’d therefore highly recommend using a texture atlas once your game gets out of the prototyping stage. Even with a 90s platformer like Go! Go! PogoGirl, this can make a huge difference.
The reason a texture atlas increases the performance of your game is that instead of loading and storing hundreds of separate image files in memory, your game only needs to keep one image handy at all times. In case you don’t know what an atlas is: It’s essentially one big image that contains all your game’s sprites, along with a text file that lists all these sprites with their names and positions within the image, so that your game can easily retrieve them. Using a texture atlas (or a “sprite sheet”, if you prefer) is one of the easiest ways to increase the performance of your game.