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.

Dark GDK / after "n" seconds ???

Author
Message
chan
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 21st Nov 2011 16:50
im doing a 2d rpg and hoping this to become mmo and i will really work for that.

but i am confused, how will i make a function execute only once per a certain number of seconds..

i was trying many codes bymyself but i only end up to crash..

please help


P.S --> my reply will delay because i just reged.

-Excellence deals with weak people-
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 21st Nov 2011 23:09
Here's a basic way:


chan
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 22nd Nov 2011 09:25
thanks, i will try this code.

-Excellence deals with weak people-
chan
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 1st Dec 2011 18:57 Edited at: 1st Dec 2011 19:00


works best.
though it is not exact because the while loop does not loop for every millisecond, i think it loops the number of frames per second for every second.


thanks alot for the idea.

sorry i just posted.

-Excellence deals with weak people-
Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 1st Dec 2011 20:24
it's not the loop, it's that GDK is pausing the program a little bit in dbSync(and/or LoopGDK) to keep the frame rate constant, to make it exact, you should use multithreading, which is pretty advanced, and not really worth it, i mean, a few milliseconds won't hurt

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Dec 2011 21:19
There's a few options you could use for timed functions.

1. You could handle it yourself and use the dbTimer function.
2. The Winapi SetTimer() function which can be setup to be used without passing a hWnd handle.

Have a look here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644901(v=vs.85).aspx as well as googling for more information on it without passing a hWnd.

Also, the Sleep() function gives a little time back to windows while suspending your program for x amount of milliseconds.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-04-26 12:13:48
Your offset time is: 2024-04-26 12:13:48