Making Animations Run the right speed.

BlitzMax Forums/BlitzMax Beginners Area/Making Animations Run the right speed.

Moogles(Posted 2006) [#1]
Ok. I got some animations right? i want my game to run at 60 fps. but my animations are meant to run at 10 fps. so that means they would run 6 times faster. what would i do to make them run the correct speed? would i have to add a Delay(360) before the flip command? 360 because 60 * how much faster it is than that animation which in this case is 6 = 360
Is that the correct way?


Dreamora(Posted 2006) [#2]
Delay is the wrong way :-)

There are 2 possibilities:

1. You use time based programming
So you check if the time difference since the last animation frame change is large enough to do a new change (100 ms if you want 10fps -> 1000 / wished_fps ms )

2. I can't guarantee that this would work with animation, but if you use a float for the image frame variable, you can raise the frame variable by frames_per_second# / actual_rendering_fps# and use that one.


undomiel(Posted 2006) [#3]
Here's one way to do it. It's rather inelegant but it should set you on the right path for creating your own elegant idea of how to do it.

SuperStrict


Graphics(800,600)

Global animationCounter:Int = 0
Global animationCount:Int = 10
Global animationFrame:Int = 0
Global maxFrames:Int = 12

Function updateAnimations()
animationCounter:+1 'increments every tick
If animationCounter >= animationCount 'once ready then we'll update which frame to display
If animationFrame < maxFrames-1 'because we want 0 - 11 not frame 12
animationFrame:+1
Else
animationFrame = 0
End If
End If

'draw all of your animations here based off the current animationFrame
'though keep in mind that with this example every animation would be running at 12 fps
'another way you could do it is to have animationCounter count through 0 - 59 and then
'just use a divide for which ticks you want your frame to be updated on for each animation


End Function

'setup your timer here
Global refreshTimer:TTimer = CreateTimer(60)

While not KeyDown(KEY_ESCAPE)
WaitEvent()
Select EventID()
Case EVENT_TIMERTICK 'gets called every 60 ticks
updateAnimations()
EndSelect
Wend
End

Off to bed for me, I hope my code doesn't look too overtly brain dead.


Moogles(Posted 2006) [#4]
thanks alot. this is alot of code and im gonna take a look at it. im thinking of how did My old programs display animations at different frame rates.
Cheers!


tonyg(Posted 2006) [#5]
Just in case...
Delta time and Anim
Wave's code
Indiepath's code
Wave code +
Wave's tutorial also has a section on timers.


Moogles(Posted 2006) [#6]
thanks. i thought no one would know how because all games that are usually made are like single images or particles.


tonyg(Posted 2006) [#7]
Not sure I agree with that but nevermind.


Smurftra(Posted 2006) [#8]
hm, i believe all games that are usually made have animations. I dont know many game that doesnt have any, exept for solitaire. :)


Moogles(Posted 2006) [#9]
i mean not all games. i mean tutorial games on this site. like scot shavers zoom and boom. and some others like asteroid where its just rotating rocks, and a little laser shooting at them. not much animation there.


Moogles(Posted 2006) [#10]
thanks udomiel. theres one thing you missed in your code. ;)
to reset the animation counter so it keeps that time between changing the frames constant. But its a great help man!