Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (773)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scaling a value based on FPS?  (Read 3362 times)
0 Members and 1 Guest are viewing this topic.
Offline CopyableCougar4
« Posted 2014-07-03 22:39:47 »

Hi

I was just wondering if there was a way to scale values based on FPS, if the entities move at fixed time intervals rather than based on frame count. For example, if player A gets 120 fps and player B gets 170 fps is there a way to scale the players speed so that both players would have an equal advantage?

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #1 - Posted 2014-07-03 22:43:32 »

You would use delta time.
Basically the time that has passed since the last update.

Then instead of moving objects a set amount per frame you would move them based on milliseconds.

example:

1  
2  
3  
4  
public void update(int deltaTime)
{
    this.x += dx * deltaTime;
}


Edit:
It's a very commonly used method for gameloops, so it should be easy to find examples on google Smiley
Offline CopyableCougar4
« Reply #2 - Posted 2014-07-03 22:44:44 »

Hi

That is probably going to be my best option Smiley Thanks Smiley

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #3 - Posted 2014-07-03 22:47:00 »

A word of caution with this method though:
If you for some reason have a huge lag spike or if you minimize the game (LWJGL) then your game will try to catch up and update with a deltaTime of thousands of milliseconds!
Not a huge problem but remember it Smiley
Offline CopyableCougar4
« Reply #4 - Posted 2014-07-03 22:49:59 »

Hi

Thanks for the word of caution, but as of now the window is fullscreen and hitting escape will destroy the display Smiley Also, as of now I took your idea and added it with only about 7-8 lines of code and it works beautifully Smiley (It was noticeable before because two different sections of the world caused different FPS counts and the speed boost used to be noticeable).

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline PandaMoniumHUN

JGO Coder


Medals: 32
Exp: 3 years


White-bearded OGL wizard


« Reply #5 - Posted 2014-07-04 17:54:40 »

I have a nice little explanation on delta time here (not very technical but it's only meant to help you understand what delta time is), if you're interested check it out. Smiley

My Blog | Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1850 views)
2018-06-10 19:43:48

EgonOlsen (1879 views)
2018-06-10 19:43:44

EgonOlsen (1244 views)
2018-06-10 19:43:20

DesertCoockie (1679 views)
2018-05-13 18:23:11

nelsongames (1344 views)
2018-04-24 18:15:36

nelsongames (1962 views)
2018-04-24 18:14:32

ivj94 (2735 views)
2018-03-24 14:47:39

ivj94 (1937 views)
2018-03-24 14:46:31

ivj94 (3028 views)
2018-03-24 14:43:53

Solater (1077 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!