Freeze FPS?

I did a search but couldn’t find anything.



Is there a way to “freeze” the FPS to 60 FPS?



I’m asking because if there isn’t much on the screen and FPS is through the roof, the player’s ship respond differently. Controls are much faster, speed is greater, etc.

Theres even a menu item for it when you start any jME3 project :stuck_out_tongue: But generally you’re doing it wrong when you are fps dependent. Thats what the tpf (time per frame) variable is for…

You shouldn’t rely on a constant FPS for your game logic. It is very likely it will go down from 60 on lower-end GPUs and then your entire game will be in slow motion.

Instead, use the TPF (time per frame) variable to make game logic framerate-independent. See the Hello Main Loop tutorial for an explanation on how to use the tpf variable.

Once you’ve confirmed that your game runs at the same speed regardless of framerate, you can put an upper limit (but not a lower limit) on the framerate by using AppSettings.setFrameRate(60)

I guess I mis-explained what I meant.



I indeed want to impose an upper limit on FPS, not an obligatory fixed point at which the FPS should run.



I will take a look at HelloMainLoop and see if that fixes my accelerated movement problem.

Well, it seems this fixed the yaw/pitch/roll depending on FPS, but for some reason it’s not working when the ship is moving. Funny enough, I already had set it so it would use the tpf when moving, but I still get unwanted acceleration that is tied to FPS.



The following is in update();



[java]

@Override

public void update() {

super.update();







if (playerShip.isShipMoving) {

v = pShipModel.getWorldRotation().multLocal(Vector3f.UNIT_Z.clone());

Vector3f newCoords = v.mult((playerShip.getShipSpeed()/tpf));

//offset to move to

pShipModel.move(newCoords);

}[/java]

madjack said:
Well, it seems this fixed the yaw/pitch/roll depending on FPS, but for some reason it's not working when the ship is moving. Funny enough, I already had set it so it would use the tpf when moving, but I still get unwanted acceleration that is tied to FPS.


The movement issue is most likely caused by a math error - you should be multiplying by the TPF, not dividing, as TPF is exactly that - time per frame. when running at a constant speed of say, 60 fps, the tpf variable will be roughly 1/60 for each frame. with update() being called once per frame, 60 times per second in this case, you should multiply all movement/rotation values by the tpf value (1/60 in the case of 60 fps) so that in a second's time, the tpf values add up to 1, and thus the movement/rotation speed is steady.
1 Like

Multiplication by tpf doesn’t do anything. If the ship moves, I cannot see it. There’s no movement discernible at all.



In hindsight I remember having tried that. That’s the reason it’s dividing.

Nevermind that…



I’ve fix it. It turned out the speed increment was so small that it wouldn’t register with a multiplication. So by “normalizing” the speed increment and multiplying, it now works perfectly.



Thanks. :smiley: