GLBasic forum

Main forum => GLBasic - en => Topic started by: quick2code on 2008-Oct-13

Title: Time Based Animation
Post by: quick2code on 2008-Oct-13
Good day,

   I recently purchased GlBasic and I've been making great progress. But I can't seem to convert any known Time Based Animation code I have to be GlBasic friendly. I'd like to slow down the animation of images even with the FPS set at 60. I've been trying for hours, and I don't see any example code in the Samples folder. Can somebody show me an example? I'm not sure if this is the right place to put this request. Thanks to anybody for any information.
Title: Re: Time Based Animation
Post by: Hemlos on 2008-Oct-13
Theres a handful of methods to do this...i dont have much time so ill be brief(someone else may provide you with working code)

Check the help files for these:
GETTIMER() <-time from last showscreen
GETTIMERALL() <-overall time
PLATFORMINFO$(TIME) <-this one you can use for tracking "seconds" changes.

What exactly do you want to do with animations? Different effects can be done with different approaches to make it accurate regardless of computer program is running on...
ie. rotations? or Zoom? or more complex overlaying 2d animations?

Title: Re: Time Based Animation
Post by: quick2code on 2008-Oct-13
Thanks for the reply. Really, all I want to do at this stage is load an animated image, set LimitFPS to 60, and slow down the frame change speed of the animation to an acceptable rate. I did look at those examples but I didn't see anything specific to this. Thanks.
Title: Re: Time Based Animation
Post by: Moru on 2008-Oct-13
You need a counter that keeps track of wich frame you are drawing on screen and one that keeps track of how many miliseconds since last time you changed frame. This is a simple example of one way to do this. I'm sure you will get more soon :-)

Code (glbasic) Select

LOCAL frame = 0
LOCAL maxframe = 8
LOCAL timer
LOCAL delay_between_frames = 50

// Load the animation into ID #1 and split it in 16x16 pixel sprites
LOADANIM "ball.png", 1, 16, 16   

timer = GETTIMERALL() + delay_between_frames // When is it time to change frame?

WHILE TRUE
IF timer <= GETTIMERALL()
frame = frame + 1 // next frame
IF frame >= maxframe THEN frame = 0 // Limit frames to no more than eight
timer = GETTIMERALL() + delay_between_frames // Set new time to change frame
ENDIF

DRAWANIM 1, frame, 50, 50 // draw the animation on the screen
SHOWSCREEN
WEND

Title: Re: Time Based Animation
Post by: MrTAToad on 2008-Oct-13
You might be interested in the timer based code from my post here : http://www.glbasic.com/forum/index.php?topic=2358.0 (http://www.glbasic.com/forum/index.php?topic=2358.0)
Title: Re: Time Based Animation
Post by: quick2code on 2008-Oct-13
Thanks guys(or girls). That's what I was looking for.