Mercurial > hg > ristipolku
comparison game/Engine.java @ 164:2b2fa62cfea5
Fix animation timing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 01 Mar 2017 13:50:50 +0200 |
parents | e8eeac403e5f |
children | 159252f9480d |
comparison
equal
deleted
inserted
replaced
163:dda7152d2402 | 164:2b2fa62cfea5 |
---|---|
590 | 590 |
591 public class Engine extends JPanel | 591 public class Engine extends JPanel |
592 implements Runnable, KeyListener, | 592 implements Runnable, KeyListener, |
593 MouseListener, MouseWheelListener | 593 MouseListener, MouseWheelListener |
594 { | 594 { |
595 long startTime; | 595 double startTime; |
596 float gameUpdates, gameFrames; | 596 float gameUpdates, gameFrames; |
597 | 597 |
598 Thread animThread; | 598 Thread animThread; |
599 boolean animEnable = false; | 599 boolean animEnable = false; |
600 | 600 |
678 dbg("Requesting focus.\n"); | 678 dbg("Requesting focus.\n"); |
679 requestFocus(); | 679 requestFocus(); |
680 } | 680 } |
681 | 681 |
682 gameUpdates = 0; | 682 gameUpdates = 0; |
683 startTime = System.currentTimeMillis(); | |
683 } | 684 } |
684 | 685 |
685 public void startNewGame() | 686 public void startNewGame() |
686 { | 687 { |
687 gameFrames = 0; | 688 gameFrames = 0; |
688 startTime = new Date().getTime(); | |
689 lauta.startNewGame(); | 689 lauta.startNewGame(); |
690 } | 690 } |
691 | 691 |
692 public void paintComponent(Graphics g) | 692 public void paintComponent(Graphics g) |
693 { | 693 { |
850 { | 850 { |
851 // Progress game animation clock | 851 // Progress game animation clock |
852 gameUpdates++; | 852 gameUpdates++; |
853 | 853 |
854 // Animate components | 854 // Animate components |
855 lauta.animate(gameUpdates); | 855 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f); |
856 lauta.animate(tmp); | |
856 | 857 |
857 // Repaint with a frame limiter | 858 // Repaint with a frame limiter |
858 if (gameUpdates % 4 == 1) | 859 if (gameUpdates % 4 == 1) |
859 repaint(); | 860 repaint(); |
860 | 861 |