Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Fixed-rate logic ticks, that can be faster than the actual framerate.
- //Horrifying in its implications. Works great until whatever's in the While loop
- //takes longer than dt...
- final float TARGET_RATE = 120.0f;
- float accumulator = 0;
- float period = 1.0f / TARGET_RATE;
- //Draw() is called in a loop, dt is the time elapsed since the last call
- public void draw(float dt) {
- accumulator += dt;
- while (accumulator > period) {
- accumulator -= period;
- //Do do stuff at 120Hz, irrespective of framerate
- //Just remember to use period anywhere you would normally use dt
- }
- //Do the rest of your logic at the game's actual framerate
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement