Understanding tpf

Can I check the proper use of tpf? Currently, I multiply all movement vectors by the tpf each frame to get a constant rate. However, if I run my app on a slower computer, the game runs slower, which I assumed the tpf would counteract. Also, suspiciously, the tpf is exactly the same every frame. I would have thought it would vary slightly? Should I implement my own game timer?


It is indeed suspicious. Are you sure you are not overwriting tpf somewhere?

What happens if you print tpf on this code http://davidb.github.io/sandbox_wiki_jme/jme3/beginner/hello_main_event_loop.html

If you use bullet you don’t need to use tpf, its framerate decoupled already, the velocity vectors are in m/s.

1 Like

I tried that code, added a simple “System.out.println(“tpf=” + tpf);”, and that outputs what I would expect, ie. a varying numbers. However, my code, which also extends SimpleApplication, has an almost identical method:-

    public void simpleUpdate(float tpf) {
        System.out.println("tpf=" + tpf);

However, the result is a stream lines all saying “tpf=0.06666667”.

This is very strange; I think I need to investigate further…

Just discovered the problem! I had

stateManager.attach(new VideoRecorderAppState());

set. Maybe this requires a consistent loop interval for recording purposes?

Yes, the video recorder will force 30fps (I think) so you have a consistent framerate output for the video, so it will slow down the rendering depending on how fast the computer is. This is mainly because the encoding causes additional overhead but can also be used as a feature to get a smooth video rendering of scenes that would normally not render fluently even without the video recording overhead.

OCam is fantastic for recording jme vids.