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 / Smooth 2D sprites with Timer()?

Author
Message
zman
22
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Madison, WI USA
Posted: 18th Oct 2003 18:26 Edited at: 18th Oct 2003 18:29
Hi all,
I imagine this topic has been beaten to death already but I can't get this to work to my satisfaction so I'm asking for your help...

I'm using the Timer() function to control a 2D sprite so that it moves at the same speed on slower/faster CPUs. The code I've written so far does that, but the movement is jerky. Is this due to timer resolution or am I doing something else wrong?

I remember all those old Amiga games where the game was locked to a 60Hz vertical refresh and everything was soooo silky-smooth.

Any help much appreciated

ReD_eYe
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 18th Oct 2003 22:36 Edited at: 18th Oct 2003 22:37
why not just set the sync rate to 60 stopping faster machines going faster than that?


"Look a bandwagon.... lets jump on it!"
zman
22
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Madison, WI USA
Posted: 19th Oct 2003 05:07
Well 'cause if I set sync rate to 60 it loses that nice smoothness--and the online help mentions that forcing the sync rate will compromise smoothness which is why I'm using sync rate 0.

Take the Shadow of the Beast demo: it uses sync rate 0 and the scrolling is rock-solid, but of course the images scroll at different speeds depending on the computer, e.g. my main PC set at 100Hz refresh scrolls the clouds faster than my second PC set to 60Hz. Change the sync rate to 60 and the clouds jitter and skip along on either machine.

So that's why I'm investigating using timers...to see if I can have my cake and eat it, too: super smooth scrolling at the same speed on different machines.

I suppose another approach would be to lock the display mode at 60Hz which nearly any PC/monitor should support...but I don't know if that's even possible with DarkBasic (set display mode takes width, height and bit depth but no provision for setting the vertical refresh?)
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 19th Oct 2003 06:36 Edited at: 19th Oct 2003 06:38
your close but what you need to do is instead of useing the timer to update the move distance, you need to use the timer to accept movement commands.



I've used something like this with my 'Zone' game, it was a overhead 2d airplane shooter, the timers controlled the speed of the planes, the speed of rotatation for the planes, and the speed of the bullets will the game refreshed as fast as it could so it had a silky smooth 360 dregree scrolling background. worked very well.
STE
22
Years of Service
User Offline
Joined: 7th Oct 2003
Location:
Posted: 19th Oct 2003 07:08
I used the attached source code (which I initially ripped off someone else who posted on this forum).

The source code won't run on it's own, but it will show you the method I use.

Essentially you store the amount of time that has passed between the last 2 frames (syncs), then vary how far to move the object based on that and the Objects speed.

The disadvantage is that it's a little messy for the first frame - so it needs some bodge code at the top, and I think it *may* go a little strange when fps reaches extreme values (<10 & >250 maybe) because the DBPro timer() precision isn't that great.

Good luck.

STE ;¬!
KOL
22
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 19th Oct 2003 07:21
Sorry CloseToPerfect,
but that does not work propely for me.



This is slower than snott.

Even if movetimerset# = 1 (or even the if statement is removed) the code is still slow

I'm on a 700 MZ labtop and I know that's faster than any Amiga I ever owned.
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 19th Oct 2003 16:42
he's using move sprite for the speed of the object, so in my example I just used hes code which is move sprite 1, .5, at 60 frames per sec it's only 30 pixels per sec or a 640 screen in about 21 secs, yes it is very slow but you can adjust the speed of move sprite. The point is if you had a background scrolling then it would be refreshing at the fastest rate possible and the game mechanics would be working at 60/fps.
Heres your code with a faster move sprite and a second sprite moving the same speed but not on the timer and you can see how much faster it moves.

CTP

KOL
22
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 19th Oct 2003 17:12
My apologies CTP,
I have not worked much with sprites and missed the finer points with the move sprite command. I will be more careful in the future.
zman
22
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Madison, WI USA
Posted: 29th Oct 2003 07:04
Thanks everyone for your replies.

CloseToPerfect your method is interesting and I hadn't thought of doing it like that. But hey what can I say, I'm greedy and I want *everything* to run super-smooth, not just a scrolling background but my sprites too.

Anyway in case anyone's interested...here is my earlier code re-written to use a high-resolution timer (QueryPerformanceCounter). The 2D animation is much smoother, and the paddle moves at the same speed on both of my PCs even though they have different CPUs, gfx cards and vertical refresh rates.

To run this code you'll first need to install the Matrix1Utility DLL which you can find here: http://www.matrix1.demon.co.uk/DBPro/TPCDLLS-downloads.html

zman
22
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Madison, WI USA
Posted: 29th Oct 2003 07:08
Also to give proper credit to IanM...I lifted the functions in that code snippet from here: http://darkbasicpro.thegamecreators.com/?m=forum_view&t=4533&b=1
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Oct 2003 09:11
I am wondering why you have the functions in there - you don't call them or need to call them, as the HiTimer() function from my plug-in does it all for you.



Hmmm, I know that the performance timer is more accurate than the standard lo-res timer we normally use, but does it really make *that* much difference? I'll have to think of some way to test them against each other.
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 29th Oct 2003 09:32
im working on some timer() commands for my game... which getting milliseconds is plenty fast for me (i could prolly use hundreths)... but my concern is what number the timer() command returns... here are my questions...

1) does the system time ever roll over to 0 when it reaches a certain number
2) returns an integer normally, will it return 'double integer' if the computer has been on for more that 24 days?

had a third question... but i doubt that someones computer will be on more than 292,471,208 years so dont have to worry about that

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro
zman
22
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Madison, WI USA
Posted: 29th Oct 2003 21:13 Edited at: 29th Oct 2003 21:14
Hey IanM, hmmm yes you're right those functions weren't needed. That was a brilliant piece of cut & paste coding on my part.

As far as whether the timer resolution matters...maybe all those old Psygnosis games on the Amiga spoiled me for any other platform, but all I can say is that my highly trained bionic eyes can see the difference. IMO it's probably less of an issue for 3D games but for 2D even a slight amount of jitter can be noticeable. Although I haven't tried it I suspect that converting the Shadow of the Beast scrolling demo to use Timer() might be an easy way to visualize the difference.

Some might frown on this but what I'd really like to do is just force the screen mode to 60Hz, run at sync rate 0 and be done with it. I believe DirectX supports specifying the refresh rate but as far as I can tell DBPro doesn't, instead it seems to use the current Windows desktop setting(?) Using this approach, really slow machines might still need an option to use a timer so that they could drop frames as needed to keep the animation speed consistent.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Oct 2003 00:45
Quote: "Some might frown on this but what I'd really like to do is just force the screen mode to 60Hz, run at sync rate 0 and be done with it"


If you want a rock-solid 60 fps, why not use the hitimer() function as it was intended and specify that you want 60 ticks per second ...



This should give you exactly what you are after
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 30th Oct 2003 04:07 Edited at: 30th Oct 2003 04:08
i worked around a bit with the timer() command dealing with moving objects and the such... go ahead and change the code to fit your needs...

usage is simply "speed (speed value, elapsed time)" there is also usage and other info in the code that is attached... hope this will help some people out!

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro

Login to post a reply

Server time is: 2026-07-26 11:42:43
Your offset time is: 2026-07-26 11:42:43