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 / The same movement speed of a sprite on different computers

Author
Message
DWD
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 11th Apr 2003 18:11
Hi there,

What would be the best way to do a short speed test of the end-user's computers in order to determine how fast a sprite should move on the screen (so the speed will be (near) the same on all computers)? Would it be by means of fps?

Cheers
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Apr 2003 18:18
DWD

You don't do a speed test, you basically do timer based movement, ie. so a sprite takes 5 seconds to move from A to B, rather than 500 frames.

Use the timer() commands for this.

Current Project: Retro Compo. Entry.
DWD
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 11th Apr 2003 18:28 Edited at: 11th Apr 2003 18:29
Thanks for your reply

Okay, but in a simple coding example of mine I e.g. write (in pseudo code):

[ pseudo code ]

speed = 5


do

paste sprite


if up then sprite_position_y = sprite_position_y - speed

// etc.


update screen

loop


[ /pseudo code ]


So instead of calculating a speed factor I should take a look at the timer() function? Okay, I will try that.

Cheers

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Apr 2003 18:31 Edited at: 11th Apr 2003 18:34
For example, this code will rotate the cube at the same speed on any machine, whether it can run the program at 20FPS, or 200FPS;


make object cube 1,20
do
a=timer()

xrotate object 1,object angle x(1)+(50*(c#/1000))
text 20,20,str$(screen fps())
sync
b=timer()
c#=b-a
loop


In the key part: 50*(c#/1000), 50 is the amount you want to move the object by (that doesn't mean 50 degrees here, it is just a value). The (c#/1000) just means that the movement is the same no matter how fast or slow the program is running.

It would be better to make this into a function.

eg:

xrotate object 1,object angle x(1)+Calc(50)

function Calc(value#)
result = value#*(c#/1000))
endfunction result


In this case though, c# would have to be a global value ( global c# at the top of your program)

If you want to test this, add sync rate 20 at the top of the program, run it, then run it with sync rate 200 at the top of the program - voila, cube rotates at the same speed on both (although the cube will rotate more smoothly if the FPS is higher).

Current Project: Retro Compo. Entry.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Apr 2003 18:40
Just a note, DO NOT use SCREEN FPS() to instead of timer() to work out c#, in my experience, that can cause pretty wild fluctuation at times. I tried it on my SpaceROADS game and the ship was moving like it was attached to a yo-yo.

Current Project: Retro Compo. Entry.
DWD
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 11th Apr 2003 18:42
Heh, yes but here you are also calculating a speed factor for the cube movement:


function Calc(value#)
result = value#*(c#/1000))
endfunction result


I think I will do the same for me sprite movement by means of the timer. This is sort of the same way I have done it in my experience in other programming languages.

Cheers

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Apr 2003 18:44
"Heh, yes but here you are also calculating a speed factor for the cube movement:"

Of course there has to be a relative speed factor. Otherwise everything would happen at the same speed.

Current Project: Retro Compo. Entry.
DWD
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 11th Apr 2003 18:47
Sorry, then I misunderstood this comment:

"You don't do a speed test"

About:

"Otherwise everything would happen at the same speed."

No, that is the problem. The speed would be different depending on which computer you are running.

Cheers

spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 11th Apr 2003 19:08
I would also do something in case last frame drew so quickly that difference in timer() values is zero and thus object doesn't move at all. It can cause a slight st.st.stutter.

Gronda, Gronda
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 11th Apr 2003 19:27
you could always force you main loop to wait until it took at least one timer() unit

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 12th Apr 2003 02:07 Edited at: 12th Apr 2003 02:11
DWD, no, the above code runs at the same speed on ANY computer - just try it.

Current Project: Retro Compo. Entry.
DWD
23
Years of Service
User Offline
Joined: 10th Apr 2003
Location:
Posted: 12th Apr 2003 19:09
Yes, in that example it will because you are calculating a speed factor, which was what I was talking about.

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 12th Apr 2003 19:29
You HAVE to calculate a relative speed factor though, there isn't any other way of making the movement happen in a given time rather than in a given number of frames.

Current Project: Retro Compo. Entry.
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 12th Apr 2003 22:32
I'm confused by some of the posts, I think some are incorrect or written in such a way i'm not following.

Anyway i'll give you my method, this one makes the game run at the same speed on all computers and allows the game to run at the fastest possible framerate for maximum smoothness.

*click on source box below*

Pneumatic Dryll, Outrageous epic cleric of EQ/Xev
God made the world in 7 days, but we're still waiting for the patch.
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 12th Apr 2003 23:57 Edited at: 13th Apr 2003 00:00
This is my method.

edit: I made an error in the attached code try this

solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 13th Apr 2003 12:53
Rob's method is more accurate than yours, the-winch,
because if your main loop has a lot of processing until you call
control_ship(), then you may pass your time limit (400) and you
don't take the real time in your considerations...

Login to post a reply

Server time is: 2026-07-11 02:35:01
Your offset time is: 2026-07-11 02:35:01