Mercurial > hg > ristipolku
comparison game/Engine.java @ 168:159252f9480d
Fix animation choppiness.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 02 Mar 2017 12:30:19 +0200 |
parents | 2b2fa62cfea5 |
children | b9bc493ae53c |
comparison
equal
deleted
inserted
replaced
167:7bf508d363bd | 168:159252f9480d |
---|---|
761 /* | 761 /* |
762 g2.setFont(G.fonts[1]); | 762 g2.setFont(G.fonts[1]); |
763 long currTime = new Date().getTime(); | 763 long currTime = new Date().getTime(); |
764 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20); | 764 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20); |
765 */ | 765 */ |
766 | |
767 Toolkit.getDefaultToolkit().sync(); | |
766 gameFrames++; | 768 gameFrames++; |
767 } | 769 } |
768 | 770 |
769 public void startThreads() | 771 public void startThreads() |
770 { | 772 { |
854 // Animate components | 856 // Animate components |
855 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f); | 857 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f); |
856 lauta.animate(tmp); | 858 lauta.animate(tmp); |
857 | 859 |
858 // Repaint with a frame limiter | 860 // Repaint with a frame limiter |
859 if (gameUpdates % 4 == 1) | 861 if (gameUpdates % 2 == 1) |
860 repaint(); | 862 repaint(); |
861 | 863 |
862 // Sleep for a moment | 864 // Sleep for a moment |
863 try { | 865 try { |
864 Thread.sleep(10); | 866 Thread.sleep(15); |
865 } | 867 } |
866 catch (InterruptedException x) { | 868 catch (InterruptedException x) { |
867 } | 869 } |
868 } | 870 } |
869 } | 871 } |