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 / Confused about timing in general, eg in animated sprite, time_t variables, etc

Author
Message
Toshio
14
Years of Service
User Offline
Joined: 10th May 2010
Location:
Posted: 12th May 2010 09:31
Hello

I feel that when I use any code that concerns about timing, it shows so slow. Let me try to explain it better.

For example:

dbPlaySprite(image, startframe, endframe, time);
from what I read, the time is in milliseconds. When I put, say, 100, it doesn't really feel like it takes me 0.1s to show next frame. Actually, I even tried putting 1, and it took me like ~ 1second to play 3 frames.

Another example problem I encountered:
I have time_t variable declared, say time_t sec;
When I try to flash a message every 0.3second by doing this:

sec = time(0);
while (needtorunthispart)
{
dbCLS();
if (time(0) - sec > 0.3)
{
dbText(100, 100, "Hello");
sec = time(0);
}
dbSync();
}

It doesn't really do that every 0.3seconds for me, but more like ~ something near every 1second. But then if i set the time larger than 1second, it seems to be right. For example, if I set it as 2 second, it seems to be able to show the message every 2 seconds no problem.

Hopefully I didn't confuse you guys with my possibly bad description. I will appreciate it if anyone could let me know where I am having mistakes on. Thank you~~
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 12th May 2010 13:26
Oh well, first off, i believe most functions that takes time input, is measured in milliseconds, not seconds, 1 second = 1000 millisecond.

Also, all you need for your timing is dbTimer();, it returns time since the application have started, for example, let's say you want your program to do an action every 2 seconds, this code should explain it:



So as you see, every 2000 milliseconds ( 2 seconds ) we set timer variable to dbTimer, and do the action

Toshio
14
Years of Service
User Offline
Joined: 10th May 2010
Location:
Posted: 13th May 2010 01:18
Thanks a lot Hassan.
I find it easier to do the timing with dbTimer() you suggested than the time_t variables I used to use. Thanks for introducing it to me.

Login to post a reply

Server time is: 2024-11-19 23:38:49
Your offset time is: 2024-11-19 23:38:49