Skip to main content
gamedev.net
🔒 Locked

Allegro Timer

Started by Grant1219 Aug 21, 2006 at 11:34 AM 2 replies 1k views
Original Post
Grant1219
Grant1219
I currently have an animation class that uses an allegro timer to control the speed of the animation, the problem is each instance of that class will need its own timer. Since allegro can only have 16 timers going at once this will be a problem. The only thing I can think of is if the animation is not currently playing then call remove_int(...) for its timer. Still if I need more than 16 animations playing at once (which I probably will), that wont help either. Any help with this would be great, thanks.
Grant1219
Grant1219
One other thing I was thinking was to use SDL's timer, but I don't know if Allegro and SDL can be in the same program because I have never tried it.
MrAccident
MrAccident
This is a problem that should probably be solved by rethinking your approach. Allegro timers on non-DOS platforms use threads, and you don't want to go throwing too many of those around, even if you don't need more than 16 timers. Also, some parts of Allegro will make use of some of those 16 timers for themselves, so you're even more limited.

The question you should ask is: why would every single animation need its own timer? Instead, you should just have one timer for your entire game, and every tick, call an update() function for all of your objects that need to be updated, including animations. Then you could have the animation class control its speed based on these updates, specifically by skipping a certain number of updates to achieve the right speed. For example, if your main timer runs at 60fps, and you have an animation that should change 5 times a second, then it just needs to change its image on every 12th update to achieve the correct speed.

This is a simple approach and should work pretty well for most purposes. Certainly better than using a huge pile of independent timers! [smile]
Grant1219
Grant1219
Yeah, I did think about that too. I'll just change the animation delay to delay a certain number of frames rather than entering miliseconds. Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.