diff options
author | Nao Pross <naopross@thearcway.org> | 2018-11-19 10:58:47 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-11-19 10:58:47 +0100 |
commit | a659fc5cfe73938731cc0b431f1c42a2fa0ed02d (patch) | |
tree | e1e5a6f81eb9818de548b6219970a33666fbf19d /src/Scene.java | |
parent | Update Scene class (and some derivates) to be abstract (diff) | |
download | Subconscious-java-a659fc5cfe73938731cc0b431f1c42a2fa0ed02d.tar.gz Subconscious-java-a659fc5cfe73938731cc0b431f1c42a2fa0ed02d.zip |
Update GameWindow and remove parent frame dependency on Scene
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); |