Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test
- //Java Game Loop implementation based on http://www.koonsolo.com/news/dewitters-gameloop/
- //java port by b5cully
- {
- static int TICKS_PER_SECOND = 25;
- static int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
- static int MAX_FRAMESKIP = 5;
- static int tickcount = 1;
- static int d; //just for simulating purpose
- public static void update( ) {
- int next_game_tick = tickcount;
- int loops;
- float interpolation;
- boolean game_is_running = true;
- while( game_is_running ) {
- loops = 0;
- while( tickcount > next_game_tick && loops < MAX_FRAMESKIP) {
- //UPDATE GAME HERE
- next_game_tick += SKIP_TICKS;
- loops++;
- System.out.println("update");
- }
- interpolation = (float) tickcount + SKIP_TICKS - next_game_tick/ (float) SKIP_TICKS;
- //DISPLAY GAME HERE display_game( interpolation );
- //use: view_position = position + (speed * interpolation)
- //in all displaying methods
- System.out.println("display " + interpolation + " " + tickcount );
- d++;
- tickcount++; //count up the ticks
- if ( d > 10000) break; //just for simulating purpose, remove this
- }
- }
- public static void main(String[] args) {
- update();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement