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.

AppGameKit Classic Chat / [SOLVED] Moving my player to frame rate

Author
Message
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 02:46 Edited at: 23rd May 2023 02:47
So I have seen other people screens that can have 200 frames per sec and more set with v-sync.

So i need a good way to get there refresh rate and set the player speed and animations to the same speed no matter what there frame rates.

I can not set sync rate due to screen tearing so I need to find a better way to set speeds slower then normal or to half there frame rates I guess?

Timmer based movement I am guessing but not to sure?

Any suggestions would help.

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd May 2023 03:31
Quote: "Timmer based movement"

the (lone) search result for Timer based movement says it well.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 03:40
I'm not asking how to do timer based movement, I am asking if I should use that or something better if anything or anything at all?

Here is the issue.

When I use timer based movement my player skips a lot and you can see the jumps all the time and flickers as the time is not always constant.

When the timer is under 1 and jumps to over 1 you can see the player flicker or jump, I guess this will never happen with a pc that will always stay over 1?

Or should I do something else?

Is there a better way to get a constant timed movement?

PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd May 2023 14:14 Edited at: 23rd May 2023 14:47
If timer based movement is done correctly, there should be only little tearing with SetSyncRate().
But maybe I'm used too much to G-Sync by now :/
Do you have a G-Sync monitor? If so, have you tried to switch off G-Sync? I've been experiencing some issues using G-Sync and Vulkan lately, see this thread:
https://forum.thegamecreators.com/thread/229121
Have you tried to use OpenGL instead of Vulkan?



PSY LABS Games
Coders don't die, they just gosub without return
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 16:49 Edited at: 23rd May 2023 16:55
This post has been marked by the post author as the answer.
PSY

Hi I figured this out and it makes a lot of sense and this needs to be shared.

First i get the pcs refresh rate by setting SetVSync(1)

then in the loop I wait a few to get the correct pcs frame rate then change the frame rate to the monitors refresh rate, then turn vsync off.



I guess the computer get's its own refresh rate and the monitors get's it own and if they clash or equal they cause tearing and jumps.

So setting your monitors refresh rate to what vsync() collected already fixes all the issues.

I tested, that setting your refresh rate to 5 under the vsync() fixes all problems, even with timer based movement.

Edit:

Now you have to set that in your loop with a flag so it is not to repeat over and over, I added a timer to collect the frame rate for 100 mil seconds.
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd May 2023 17:52
Hey Game_Code_here,

Setting SetSyncRate() will automatically disable VSync, so you don't need to call SetVSync(0) after that.
I'm gonna try the -5 reduced sync rate, should I run into tearing problems. Thanks for the info!

Do you use OpenGL or Vulkan for rendering?
Using OpenGL fixed all my stuttering / tearing problems so far, even with SetSyncRate ( 0, 1 ) and using GetFrameTime() for time based movement...

PSY


PSY LABS Games
Coders don't die, they just gosub without return
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 18:06 Edited at: 23rd May 2023 18:11
Quote: " don't need to call SetVSync(0) after that"


Yes you do and after you collect it you do need it any longer.

The render does not matter in screen tearing as it is a display problem not a render problem.

So no matter what you use to render it works.

I tested it on all renders.

So this is what I am doing, step by step.

In the main before anything

You might get tearing at first, but then nothing, what i do is set my screen to be black till it is set.

SetVSync(1)

then I set a timer in my loop



So I am getting the vsync then setting my sync rate to that then setting my vsync off. No tearing.
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd May 2023 19:37 Edited at: 23rd May 2023 19:38
I do have G-Sync, and as soon as I switch from Vulkan to OpenGL, the tearing completely disappears. I'm using SetSyncRate ( 0,1 ) and GetFrameTime().
It's just strange that you need to set SetVSync(0) after SetSyncRate(), because help says :
Quote: "Using SetSyncRate will automatically turn VSync off since the two commands would fight each other for control of the frame rate."


I'm gonna do some test on my other system which doesn't support G-Sync.

Thanks again for the explanation!


PSY LABS Games
Coders don't die, they just gosub without return
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 20:28 Edited at: 23rd May 2023 20:29
Well i do not have GSync and others will not have it so I would not use it for building or testing.

Use native commands for others.

Turn that off and try to use what i just showed you, it works on every device I tried.

One last thing to worry about.
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd May 2023 21:52
I always test with and without G-Sync so that I am on the safe side.
I also never use Vulkan as the default renderer, as the OpenGL renderer runs more reliably for me.
If I ever have problems with tearing, I will definitely try your approach.


PSY LABS Games
Coders don't die, they just gosub without return
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 23rd May 2023 21:54
The only thing I noticed is it does not always load with the same frame rate in every place I load into, So You will have to make sure where your player loads gets the best frame rate or full frame rates.

Login to post a reply

Server time is: 2024-04-25 01:57:34
Your offset time is: 2024-04-25 01:57:34