Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Timer Based Movement in 2D Game

Author
Message
puppysss
19
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 4th Jul 2011 08:12
Hi,recent I figured how to apply timer based logic to 2d game.
I know the logice - old timer is needed for new timer
here exmaple

ex)
Init:
...
global ot as
global gt as dword
ot = timer()
...
update:
gt = timer() - ot
sprite 1 , " I don't know how to do " , "same..." , 1
...

but I really don't know there
how do you solve them? calculate a time factor? add to them?
or occur new timer for movement?
plz help !!

Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 4th Jul 2011 10:37
The basic way is just to store the current TIMER() in a variable (before a DO/LOOP). A check within the DO/LOOP to see if the current TIMER() is more than the variable + however many milliseconds you wish the timer to be. Then make the variable equal the current TIMER() to do it again.



Another way is reducing the TIMER() down to actual seconds by using the formula (TIMER()-oldtimer)/1000 to get the seconds elapsed from the stored timer vs the current TIMER().



puppysss
19
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 4th Jul 2011 13:22
Thanks!
So do all sprites draw to the loop?
like
?

and if i need that moving is when i pressed a key,how do i solve it?

Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Jul 2011 12:30
I personally find the timer() function is not accurate enough for TBM, I use IanM's Matrix Utility plugin (free) and the hitimer() command which can be far more accurate if needed.

Quote: "So do all sprites draw to the loop?"

To draw sprites you need to use the various sprite commands in the loop such as "sprite" and / or "paste sprite".

Quote: "and if i need that moving is when i pressed a key,how do i solve it?"

I suggest you look at a few tutorials and get the hang of using sprites. Try here: http://forum.thegamecreators.com/?m=forum_view&t=115633&b=7

I see you have been a member for a long time but you seem to be asking some basic questions here (no offense). Are you new to 2D or to DBP in general?

If you have experience in 3D you will find 2D relatively similar. Familiarise yourself with the sprite commands and you'll see what I mean.

puppysss
19
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 6th Jul 2011 13:53
thanks to you,I can avoid timer accuracy problem!! Thansk!!

Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Jul 2011 14:00
Glad to help

Login to post a reply

Server time is: 2026-07-11 02:36:21
Your offset time is: 2026-07-11 02:36:21