diff options
Diffstat (limited to '')
-rw-r--r-- | src/Scene.java | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/Scene.java b/src/Scene.java index 529a2f6..d8c826e 100644 --- a/src/Scene.java +++ b/src/Scene.java @@ -23,28 +23,20 @@ public abstract class Scene extends JPanel protected final long DESIRED_FPS = 60; protected final long DESIRED_DELTA_LOOP = (1000*1000*1000)/DESIRED_FPS; - // TODO: lowercase not constant values - protected int WIDTH; - protected int HEIGHT; protected BufferStrategy buffer; - // TODO: remove frame reference - protected JFrame frame; + protected Dimension canvasSize; protected boolean running; protected Canvas canvas; // TODO: make accessible from user settings protected int guiSize = 2; - protected Scene(JFrame frame) { - this.frame = frame; - // getting window size - this.WIDTH = (int) this.frame.getSize().getWidth(); - this.HEIGHT = (int) this.frame.getSize().getHeight(); - + protected Scene() { + this.canvasSize = GameWindow.WINDOW_SIZE; this.canvas = new Canvas(); - this.canvas.setBounds(0, 0, this.WIDTH, this.HEIGHT); + this.canvas.setBounds(0, 0, this.canvasSize.width, this.canvasSize.height); this.canvas.setIgnoreRepaint(true); this.canvas.addKeyListener(this); @@ -74,11 +66,6 @@ public abstract class Scene extends JPanel while (running) { beginLoopTime = System.nanoTime(); - // TODO: use WindowEventListener to wait for changes - //getting window size - this.WIDTH = (int) this.frame.getSize().getWidth(); - this.HEIGHT = (int) this.frame.getSize().getHeight(); - this.render(); lastUpdateTime = currentUpdateTime; @@ -100,6 +87,15 @@ public abstract class Scene extends JPanel } } + // automagically set the canvas size to the parent's size + public void updateCanvasSize() { + this.canvasSize = this.getParent().getSize(); + } + + public void setCanvasSize(Dimension newSize) { + this.canvasSize = newSize; + } + protected abstract void render(); protected abstract void update(int deltaNanoTime); |