|
ALLEGRO_ANIMATED_BITMAP |
count
Member #5,401
January 2005
|
EDIT: Hi, as posted in this thread I wanted to think about an animated bitmap and so I wanted to show what I came up with. 1) How you use it.
2) The code behind it
Just the first version of the code. So what do you think about it?
|
SiegeLord
Member #7,827
October 2006
|
How do you specify ping-pong animations? Looping vs nonlooping? Variable frame-rate? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Matthew Leverton
Supreme Loser
January 1999
|
With what respect do you want us to comment? If by the AD forum, you mean included as part of A5, then I say no. This is something that is hard to abstract away. To do it right, you need a complete framework, which really isn't the same thing as a library (add-on or not). |
count
Member #5,401
January 2005
|
Quote: How do you specify ping-pong animations? Looping vs nonlooping? Didn't think of that. But possible. Quote: Variable frame-rate? Thats one thing I haven't solved yet. Any ideas? Quote: With what respect do you want us to comment? If by the AD forum, you mean included as part of A5, then I say no. This is something that is hard to abstract away. To do it right, you need a complete framework, which really isn't the same thing as a library (add-on or not).
Yea, I was looking for that kind of comment. But not only. Would you care to elaborate why this wouldn't fit in a library - or better - why this would need a framework?
|
Matthew Leverton
Supreme Loser
January 1999
|
I'm not going to try to define fuzzy terms like "framework," but the point is that there are many ways to do an animated bitmap. To me, the things that should belong in Allegro 5 core or first class add-ons are things that are a) very complex (playing sound) or b) easy to agree on a standard method (loading a PNG file, getting clipboard data). As soon as one person submits his version of animated bitmaps, somebody else is going to want to submit his own version. Then you have to decide which is better, when in reality they may just be different (and incompatible). Essentially, I think it's just too high level of a concept. I think that it's something that people will find useful if they like your methodologies, but I think we should be careful about adding all sorts of things like this to Allegro just because we can. |
Evert
Member #794
November 2000
|
Quote: Essentially, I think it's just too high level of a concept. I think that it's something that people will find useful if they like your methodologies, but I think we should be careful about adding all sorts of things like this to Allegro just because we can. I agree. Which isn't to say you can't provide something like that in the form of a third party addon. That would be good. We like third party addons. |
count
Member #5,401
January 2005
|
Ok. Sounds reasonable. I will try to add the features SiegeLord mentioned tomorrow.
|
ImLeftFooted
Member #3,935
October 2003
|
For those interested, I'm going to ramble on about animation libraries. Take, for instance, this simple sprite character. Here is the datafile for the sprite, located at datafile.txt for a nice reference (shown below).
When the sprite starts walking right the display switches to walk_right at the first frame. After 125 milliseconds the next frame is shown and so on. The system needs to be smart enough to accept events that cause a frame to start over at frame 0 and loop from there. You also need to be able to "run once" and quit. Another thing to consider: What if the game pauses? In certain cases the animations should pause as well. Also, what if the computer goes to sleep for some length of time and returns? This last one is a harder problem that I think is mostly safe to ignore though an easy solution would be worth considering. |
Milan Mimica
Member #3,877
September 2003
|
You should to it in spirit of A5 - emit an event when an animated bitmap is updated.
-- |
Trezker
Member #1,739
December 2001
|
I think you should have ALLEGRO_ANIMATION to which you can load an animation file. Thus you can use the same animation at different speeds and loop settings at the same time. |
count
Member #5,401
January 2005
|
Quote: For those interested, I'm going to ramble on about animation libraries. Will have a look at this. Thanks! Quote: Another thing to consider: What if the game pauses? In certain cases the animations should pause as well. If the game pauses then it shouldn't call the update methods for any of its containing objects. Not doing so causes the animation to pause too. Quote: Also, what if the computer goes to sleep for some length of time and returns? This last one is a harder problem that I think is mostly safe to ignore though an easy solution would be worth considering. After such a case the delta time would be huge updating the bitmap accordingly and correct. Or I misunderstood you here. Quote: You also need to be able to "run once" and quit.
I will add nonlopping animation today after work. What do you mean with quit? Quote: You should to it in spirit of A5 - emit an event when an animated bitmap is updated.
Ok. Will have to look into that. EDIT: Quote:
I think you should have ALLEGRO_ANIMATION to which you can load an animation file. Thus you can use the same animation at different speeds and loop settings at the same time. Don't think I get what you mean here. Could you explain a little bit more?
|
Audric
Member #907
January 2001
|
Most games needs much more than just sprite number + duration on each frame. Each game has different needs, so the best system for a tactical RPG isn't going to be good for a VS fighting game or a platform shooter. |
count
Member #5,401
January 2005
|
Yea. But originally I only wanted to do an animated bitmap. That has nothing to do with all the collision stuff... but i get you point here. But this proofs why it would be a bad idea to integrate something like that into allegro.
|
Trezker
Member #1,739
December 2001
|
I give code example.
|
count
Member #5,401
January 2005
|
Ah, ok. Now I got it. I like the idea. What I don't see is how a variable frame rate would be possible with this.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: What I don't see is how a variable frame rate would be possible with this.
You can take a look at a C++ animation example I coded up a while ago : Look at the AnimBase::AdvanceTime function to see what I did for it. All you have to do is store the frame rate in seconds per frame and store the residual time accumulated so far. When it exceeds the frame rate, advance by the correct number of frames using division and then assign the residual time a new value using modulus and the frame rate. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Kotlet
Member #10,714
February 2009
|
I am currently coping with bitmap animation as well. Ideas spread by you guys around the forum helped me a lot, thank you all. In my opinion Trezker's idea is very interesting. Keeping bitmap sequences and animation instances separate makes stuff more flexible. Keep them in two data structures in some animation manager object and you got everything simple and under control. |
count
Member #5,401
January 2005
|
Ok, a new version is finally available. What's missing: 1) So again first how you would use it:
2) the code
So again, comments, ideas, feature requests welcome!
|
Milan Mimica
Member #3,877
September 2003
|
I don't think you need events any more.
-- |
GullRaDriel
Member #3,861
September 2003
|
You should include a check and a destroy_animation call into destroy_animation_instance. I mean:
I probably messed up something, but the idea behind that is that when you make a call to destroy_animation_instance it also check and destroy the frames if needed. Hoping you get what I mean "Code is like shit - it only smells if it is not yours" |
count
Member #5,401
January 2005
|
Yea, I get what you mean. BUT then I thought about it, and one animation could be part of MANY animation_instances (that's the point of the animation_instance). So only beacuse I destroy one instance I can't destroy the contained animation. Hope that makes sense? Quote: I don't think you need events any more. How comes that?
|
ImLeftFooted
Member #3,935
October 2003
|
What would be really great is datafile integration. |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: You should include a check and a destroy_animation call into destroy_animation_instance. Maybe I'm just being stupid, but why in the hell would you want to destroy the ANIMATION when you're just freeing the ANIMATION_INSTANCE? Other ANIMATION_INSTANCES could be using that ANIMATION at the time, or you may want to use it again after the call to destroy_animation_instance. -- |
count
Member #5,401
January 2005
|
No, not stupid at all. Quote: and one animation could be part of MANY animation_instances (that's the point of the animation_instance). So only beacuse I destroy one instance I can't destroy the contained animation.
Quote: What would be really great is datafile integration.
Wow, didn't think of that. Nice idea!
|
ImLeftFooted
Member #3,935
October 2003
|
.gif Import and stuff. |
|
|