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.

Newcomers AppGameKit Corner / vsync(1) and timerbased movement

Author
Message
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 22nd Feb 2018 13:54
What does vsync() in detail?
Only handle the refresh depend on the monitor framerate?

If i would move all sprites the same on different hardware have i to handle it with timers?
Or are there any problems?
smallg
Valued Member
12
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 22nd Feb 2018 16:58
it tries to limit the frame rate/update time of your app to your monitor rate (normally 60 but can be 59 or even up to 240) so that's how many times it will update what is on screen in 1 second.
if your app is running slower then it will not really have any effect.

as vsync() can change based on which monitor is used it's better to use SetSyncRate(60,1) if you want 60fps for a more reliable outcome.

if you know the fps of your app you can use either method of movement.
a timer for 1 second or during 60 frames at 60fps is the same
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 22nd Feb 2018 18:50 Edited at: 22nd Feb 2018 19:03
Okay now i´m confused.
I never befor have to adjust these settings.
I used SetSyncRate(60,1) but my sprites are stuttering and with vsync(1) all is fine.

At last i wish that it runs on all machines with the same speed and no stuttering.
In this case i need more explantation.

And...
Quote: "if you know the fps of your app you can use either method of movement.
a timer for 1 second or during 60 frames at 60fps is the same"

How i can find how many fps my app have?
Do you mean if i use timerbased movement?

Or should i use a timer on first for all movements so that all movements are 60x per second and then SetSyncrate(60, 1)? It could be wrong.....

This area is newland for me.
Maybe a little codesnippet for better understanding.
Thank you in advance
Carharttguy
1
Years of Service
Recently Online
Joined: 8th Jul 2016
Location: Belgium
Posted: 22nd Feb 2018 19:32
See the official timer based movement here: https://www.appgamekit.com/documentation/examples/timers/1_timer_movement.htm
Also, instead of timer based movement, you can also use the fps to calculate speed.

Let's say you want to move something 5px per frame, just do this:
a number / CurrentFPS

Start from a steady 60 fps
300/60 = 5

If your frame speed drops to 30
300/30 = 10

You see, the latter will be the double, but your frame rate is half, so it comes down to the same. After 2 frames you will be 10 px further.
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 22nd Feb 2018 20:17
Thats clear now.
I try it tonight in code.

Lets summary.VSync() ever sets the fps to the framerate from the monitor.
In this case i have to check with ScreenFPS ( or GetFrameTime ) and then i have to adjust the movement to this fps.

In case of SetSyncRate(x, 1) i do the same for the timermoving, but i can set the fps myself.
Correctly?
I hope i have it correct understand now.

And if then another question.
If i set the framerate to 60 and the monitor i.e. uses 75 what happens?
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 22nd Feb 2018 22:29
I am finished with my ideas.
I've managed a pretty respectable movement.
It runs equally fast with 60 or 120 FPS.
But again and again the sprite starts to jerk.
Sometimes right at the beginning and sometimes only after 10 to 20 seconds. Very sporadic and I can not explain why.
How can you handle this, because it's no fun to know that you'll end up with a jerk in the game.
I have tried different Movements, but the problem remains.
I have also seen other games that were programmed with AGK.
An example with tweening is also available in the forum where three planes fly from left to right, where it jerks 2-3 times in flight from left to right.
Can it be that it is up to AppGameKit itself?
Here the testcode and of course attached for testing.
Can anybody say me how can i fix that jerking?

Attachments

Login to view attachments

Login to post a reply

Server time is: 2018-06-24 21:18:14
Your offset time is: 2018-06-24 21:18:14