finally a contribution from Schade Studios.
I`ve been tinkering around with spritesheets lately and it comes down to the fact that Tiled Background really is an alternative if you need dynamically loading textures for all kinds of game assets. It is really flexible, especially if you want to charge up new gfx at runtime. On top of that, proper usage can save a whoppin' amount of V-RAM.
Let`s say, you use the ordinary sprite for animation of your game`s main character. The character sprite is most of the time around 70-80p in both width and height, that�s already a sh*t if you have let`s say 50 frames in total. Construct will reserve 3,2 MB of VRAM (128x128 for the next power of two size * 4 byte * 50 frames) at just to display this single character. Things can add up quickly if you have more of those characters at hand.
With the proper technique, you can squeeze all 50 frames of 70x70s or whatever on one single 512x512 image, let`s say with 1 pixel margin and address them through construct. A 512x512 will use only 1 MB of V-RAM. In that example it would be a saving of around 2 MBs of V-RAM, that`s something like... well... PROFIT!!!111oneoneeleven.
It comes at some cost, though, namely CPU time. Since we cannot use Construct`s built-in cycling through image banks, we must use our own routine to find the correct sprites on the sheet, animate them, and so on.
No blatant advertising intended, but I found TexturePacker (code-and-web.de) to be the perfect tool to create Spritesheets. It also exports to various formats of Game Development frameworks. Unfortunately, Construct Classic doesn`t come with a routine for spritesheets, but what I did is that I used the general XML export of TexturePacker and wrote my own.
Basically, TP does all the dirty work, you just have to provide the following:
1. A folder containing your sprites with a proper enumeration in the filename (e.g. fire_1.png, fire_2.png and so on)
2. After trimming and all that stuff, TP has to generate a power-of-two image out of all of your sprites, and a Generic XML.
That XML contains the following:
-Some, for our purposes, more ore less useless header stuff
-And the meta data, it looks like:
<Image Name="Crossbow 1" Height="70" Width="77" YPos="1658" XPos="871"/>
Image Name=the original filename (useful for later reference)
Height=Absolute Height of the sprite
XPos=X Position of the sprite on the sheet
That`s the basics. TP is also able to output the original frame size of the single images, allowing pixel-perfect size the sprite later on and offsetting it from the original size, so the animation boundaries don`t cause the sprite to jerk around whilst being animated.
I will get to that tomorrow, it`s pretty late already.
I have created a basic example on how to load a sprite sheet and address it in order to animate a game character with it.
Grab it HERE.
Props, slops and comments welcome ;)