diff --git a/src/main/java/WindowOfFreeMove.java b/src/main/java/WindowOfFreeMove.java index 34a3e0a..c1622ee 100644 --- a/src/main/java/WindowOfFreeMove.java +++ b/src/main/java/WindowOfFreeMove.java @@ -12,6 +12,7 @@ public class WindowOfFreeMove extends JFrame { private static boolean canPersonMove; private static boolean preventDoubleMove; + private static boolean isReadyToPaint; static final int KEY_LEFT = 37; static final int KEY_UP = 38; @@ -49,6 +50,7 @@ public class WindowOfFreeMove extends JFrame { } public WindowOfFreeMove() { + isReadyToPaint = false; canPersonMove = true; preventDoubleMove = true; lp = getLayeredPane(); @@ -131,6 +133,7 @@ public class WindowOfFreeMove extends JFrame { setMap(m1); map.createMap(); + isReadyToPaint = true; // // lp.remove(dialogBar); // @@ -156,7 +159,7 @@ public class WindowOfFreeMove extends JFrame { //setCanPersonMove(false); // lp.add(jf, JLayeredPane.POPUP_LAYER); - timer = new Timer(5, new ActionListener() { + timer = new Timer( 16, new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (!map.getPerson().getIsMoving()) { @@ -171,16 +174,18 @@ public class WindowOfFreeMove extends JFrame { static class Canvas extends JPanel { @Override public void paint(Graphics g) { - super.paint(g); - Graphics2D g2D = (Graphics2D) g; - g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - for (Cell cell : map.getBlocks()) { - cell.paint(g2D); - } - map.getPerson().paint(g2D); - for (Cell cell : map.getMoveToCells()) { - cell.paint(g2D); + if (isReadyToPaint) { + super.paint(g); + Graphics2D g2D = (Graphics2D) g; + g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + for (Cell cell : map.getMoveToCells()) { + cell.paint(g2D); + } + map.getPerson().paint(g2D); + for (Cell cell : map.getBlocks()) { + cell.paint(g2D); + } } } }