Ok, here is how it works:
1. First, you need to extract all the animation frames and export it as a series of image files. (There are several programs able to do this.)
2. Open every single image file in your favourite imaging program, and create an alpha channel for it. Most program can create alpha channel automatically by recognizing your luminance value. (Yes, this is indeed a very tedious tasks especially when there is a lot of images.)
3. Choose a range of image number reserved for that particular texture animation, say #100 till #170.
4. Preload all the images into that range.
5. Initialize a variable to keep track of your current animation frame, and set it to the first animation frame image number, e.g.
curAnimFrame as float
curAnimFrame = 100
You noticed that I used float instead of integer. You will know why later when comes to keeping track of the animation timing.
6. Initialize another variable that store your animation timing. It will be the amount animation frame advancement per game loop execution. You must take SYNC RATE into account when calculating this. e.g.
- If you sync rate is at 60 frames per second.
- And you want your animation advances at 6 frames per second
- Thus this variable will have the value of 6/60 = 0.1, e.g.
animTiming as float
animTiming = 0.1
- You can read this as, during every frame of the game loop, the animation advance 0.1 frame. Thus, after 10 times in the game loop, the animation will advance from the current frame to the next frame. Since the sync rate is at 60 FPS, you animation will be 6 FPS.
- You might already noticed, this is not a very accurate calculation to maintain the animated texture speed, since we didn't consider the delay in other computational tasks. We naively assumed that the game loop is always consistent at the specified SYNC RATE. This is tolerable if you don't required a super accurate timing for your animated texture.
7. In your game loop, it will look something like this.
do
`some other game processing tasks...
texture object objNum, int(curAnimFrame)
curAnimFrame = curAnimFrame + animTiming
sync
loop
Conslusion, this might not be the neatest solution available. You might want to optimize it further by don't texture the object if the current frame is same as previous. Now, it is obvious that this will eventually very messy when you have a lot of animated texture.
Good luck!
Bad Nose Entertainment - Where games are forged from the flames of talent and passion.
http://www.badnose.com/