Texture Atlases and animated images?
Monkey Forums/Monkey Programming/Texture Atlases and animated images?
| ||
Hi all, so I know I can use LoadImage with various flags to use in an animation strip, which is what I do in BlitzMax. However, in Monkey I want to start using TexturePacker and I wondered how people are handling animations when all the individual frames are packed into an atlases but at random (optimised) positions? If you have an atlas you need to use GrabImage to pick out the various images you want to use, but again GrabImage expects animations to be in a strip. Is it possible to grab each frame *individually*? So grab the first frame from a certain position, then grab the second frame from another position and so on. Yet all these frames need to properly be in a single Image instance but on the correct frames? I'm guessing it's probably possible with a module hack to expose the ability to add individual frames onto an Image instance. I haven't used texturepacker yet, just heard about it. I'm assuming it also trims your images to optimise space (or perhaps that's a setting you can toggle?). If each frame in an animation was trimmed it could create a bit of a problem when drawing them (they'd jiggle all around due to the trimming). Anyone know about this? I guess the other option is to still put the animations in an animation strip and then get texturepacker to treat it as a single (untrimmed) image and try to fit it onto the atlas, then GrabImage would work fine with multiple frames. Thoughts? Thanks! |
| ||
The way I would do it is have an animation definition class. Something like: Class AnimDef field name '<-- walk, run, attack,ect field typ '[loop_anim, run_once, ping_pong, ect] field frames%[] '<-- a list of texture atlas indices End AnimDefs are just held in a global list Then, each animating game object gets an 'Animator' object. the Animator object holds a reference to what animDef it uses. along with the current frame it using. It will also have an 'Update' method that's called when the frame changes (depending on it's loop type). I hope that makes sense. |
| ||
Yeah makes sense thanks. I thought about doing something like that too, it's just a shame not to use the build in frames functionality of Monkey images. |
| ||
Forget everything about frames monkey provides you with and just load in every image as a single one via GrabImage. Texture Packer will save a text file that has the exact positions so all you need to do is this (in pseudo code): LoadBigImage LoadTextFile 'That describes where each frame is For Each frame in BigImage frame = BigImage.GrabImage(x, y, width, height) Next |
| ||
Is this how you ended up implementing it Grey? I am also interested in using a texture atlas, but haven't found any tutorials for doing so. |
| ||
It would be great if someone could post a working example for texture atlas. (Currently I'm using separate images) |