Skip to content

Commit

Permalink
Make GridRenderer more robust if there is no camera set
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Jan 21, 2021
1 parent 1d6a691 commit 10298b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions utiliti/src/de/gurkenlabs/utiliti/renderers/GridRenderer.java
Expand Up @@ -7,6 +7,7 @@

import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.environment.tilemap.IMap;
import de.gurkenlabs.litiengine.graphics.ICamera;
import de.gurkenlabs.utiliti.components.Editor;

public class GridRenderer implements IEditorRenderer {
Expand All @@ -18,10 +19,11 @@ public String getName() {
@Override
public void render(Graphics2D g) {
// render the grid
if (Editor.preferences().showGrid() && Game.world().camera().getRenderScale() >= 1 && Game.world().environment() != null) {

final ICamera camera = Game.world().camera();
if (Editor.preferences().showGrid() && camera.getRenderScale() >= 1 && Game.world().environment() != null) {
final IMap map = Game.world().environment().getMap();
if (map == null) {

if (map == null || camera == null) {
return;
}

Expand All @@ -30,7 +32,7 @@ public void render(Graphics2D g) {
for (int x = 0; x < map.getWidth(); x++) {
for (int y = 0; y < map.getHeight(); y++) {
Shape tile = map.getOrientation().getShape(x, y, map);
if (Game.world().camera().getViewport().intersects(tile.getBounds2D())) {
if (camera.getViewport().intersects(tile.getBounds2D())) {
Game.graphics().renderOutline(g, tile, stroke);
}
}
Expand Down

0 comments on commit 10298b0

Please sign in to comment.