From 5eeda51a56148c8f6b83bbc7598b1bd8ed176a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista?= Date: Fri, 8 Jun 2018 20:12:34 +0000 Subject: [PATCH] =?UTF-8?q?nova=20l=C3=B3gica=20p/exibi=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jbatista/batatinha/EmulatorController.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/jbatista/batatinha/EmulatorController.java b/src/main/java/com/jbatista/batatinha/EmulatorController.java index 5ea54b2..d0affc8 100644 --- a/src/main/java/com/jbatista/batatinha/EmulatorController.java +++ b/src/main/java/com/jbatista/batatinha/EmulatorController.java @@ -82,13 +82,17 @@ public void handle(long now) { bufferPosition = 0; scale = (chip8.getDisplay().length == 2048) ? 8 : 4; + // clear screen + canvas.getGraphicsContext2D().setFill(backgroundColor); + canvas.getGraphicsContext2D().fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); + + // draw pixels + canvas.getGraphicsContext2D().setFill(pixelColor); for (int iy = 0; iy < canvas.getHeight(); iy += scale) { for (int ix = 0; ix < canvas.getWidth(); ix += scale) { - canvas.getGraphicsContext2D().setFill( - (chip8.getDisplay()[bufferPosition++] == 0) - ? backgroundColor - : pixelColor); - canvas.getGraphicsContext2D().fillRect(ix, iy, scale, scale); + if(chip8.getDisplay()[bufferPosition++] == 1){ + canvas.getGraphicsContext2D().fillRect(ix, iy, scale, scale); + } } } }