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 / Syncing with ms instead of fps

Author
Message
KraXarN
8
Years of Service
User Offline
Joined: 21st Apr 2016
Location: Sweden
Posted: 7th May 2016 17:54
Hello!

So, I'm working on a platformer game in AppGameKit which I works fine until I change the frame rate. I currently just have a simple "do Sync() loop" for updating and moving everything. Problem is that if the frame rate is higher, the faster that will update and then result in everything running too fast and the opposite. Is there a way to change it to like update it every ms or something similar instead of setting a fixed fps lock?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th May 2016 18:09
You should set a multiplier each cycle like so:

mult# = getFrameTime() / desiredFrameTime#

and multiply all of your movements by this. It will counteract any changes in FPS. desiredFrameTime# is the frame speed that you have set all of your movements to be based on. For example 0.016667 for 60FPS.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
KraXarN
8
Years of Service
User Offline
Joined: 21st Apr 2016
Location: Sweden
Posted: 8th May 2016 21:23 Edited at: 8th May 2016 21:26
I tried it and it still doesn't really work. When framerates get low, all values get really low...
The frametime for 165 fps, which I made it for, is 0.006 so I made it
mult# = GetFrameTime() / 0.006
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th May 2016 22:30 Edited at: 8th May 2016 22:30
What do you call slow?

If it drops to 120FPS, then mult# will be 1.38.
If you multiply any movement values by this, then they will move 38% further.

Are you applying your current position as a decimal? If you apply it as an integer, then you can lose a significant part of your movement. Don't think in pixels, think in absolute positioning.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
KraXarN
8
Years of Service
User Offline
Joined: 21st Apr 2016
Location: Sweden
Posted: 9th May 2016 14:59 Edited at: 9th May 2016 15:19
I tried syncing it up with 120 fps instead, since it will be easier to compare to 60 and 30 fps.
DesiredFrameTime is now at 0.08334,. which means that mult# is at 1. When I then set it to 60 fps, the frametime sets to 0.016667 and mult# is being set to 2.
I'm applying the current position of the player's current position + or - a set speed which is set differently so I can have momentum and stuff. Everything is set with floats

I think there's something else weird with my code, so I'll have to look more into it. Thanks for the help anyway!

Edit:
So, after just testing around, it seems to be something with how I calculate my gravity... How I do it now is that I have a vsp (vertical speed) value that controls how much Y is going to be changed. When you jump, it's being set to a set value and decreased by a set value all the time. The jump value and gravity is affected by the mult# value. Should I do this differently?
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th May 2016 11:46
What I do, is more like this, I restrict movement to a timer. Here is some example code.


13/0

Login to post a reply

Server time is: 2024-11-24 02:08:08
Your offset time is: 2024-11-24 02:08:08