Commits

Anonymous committed 5a3f8d9

switched TileDisplay to upper-left origin

Comments (0)

Files changed (2)

src/main/java/net/fishbulb/jcod/Console.java

     public void flush() {
         // blit tiles from cells (upper-left origin) onto display (lower-left origin)
         if (display == null) return;
-        for (int y = 1; y <= height; y++) {
+        for (int y = 0; y < height; y++) {
             for (int x = 0; x < width; x++) {
-                display.setTile(x, height - y, cellAt(x, y - 1).tile);
+                display.setTile(x, y, cellAt(x, y).tile);
             }
         }
     }

src/main/java/net/fishbulb/jcod/display/TileDisplay.java

 
 import static java.lang.Math.abs;
 
-/**
- * Note: unlike a Console or Tileset, which place the origin in the upper-left corner, a TileDisplay's origin is at the
- * lower left, consistent with everything else in GDX
- */
 public class TileDisplay extends Widget {
 
     // we can't call these width or height because those are Actor properties
             Drawable bgGlyph = bgTile.getGlyph();
             for (int x = 0; x < columns; x++) {
                 for (int y = 0; y < rows; y++) {
+                    int yy = (rows - y - 1);
                     Tile tile = tiles[x][y];
                     if (tile == null) continue;
                     batch.setColor(tile.bgColor());
-                    bgGlyph.draw(batch, xPos + (x * tileWidth), yPos + (y * tileHeight), tileWidth, tileHeight);
+                    bgGlyph.draw(batch, xPos + (x * tileWidth), yPos + (yy * tileHeight), tileWidth, tileHeight);
                 }
             }
         }
         // draw foregrounds
         for (int x = 0; x < columns; x++) {
             for (int y = 0; y < rows; y++) {
+                int yy = (rows - y - 1);
                 Tile tile = tiles[x][y];
                 if (tile == null) continue;
                 Drawable glyph = tile.getGlyph();
                 batch.setColor(tile.color());
-                glyph.draw(batch, xPos + (x * tileWidth), yPos + (y * tileHeight), tileWidth, tileHeight);
+                glyph.draw(batch, xPos + (x * tileWidth), yPos + (yy * tileHeight), tileWidth, tileHeight);
             }
         }
     }
             Drawable bgGlyph = bgTile.getGlyph();
             for (int x = 0; x < columns; x++) {
                 for (int y = 0; y < rows; y++) {
+                    int yy = (rows - y - 1);
                     Tile tile = tiles[x][y];
                     if (tile == null) continue;
                     cur.set(tile.bgColor());
                     batch.setColor(cur.mul(base));
-                    bgGlyph.draw(batch, xPos + (x * tileWidth), yPos + (y * tileHeight), tileWidth, tileHeight);
+                    bgGlyph.draw(batch, xPos + (x * tileWidth), yPos + (yy * tileHeight), tileWidth, tileHeight);
                 }
             }
         }
         // draw foregrounds
         for (int x = 0; x < columns; x++) {
             for (int y = 0; y < rows; y++) {
+                int yy = (rows - y - 1);
                 Tile tile = tiles[x][y];
                 if (tile == null) continue;
                 Drawable glyph = tile.getGlyph();
                 cur.set(tile.color());
                 batch.setColor(cur.mul(base));
-                glyph.draw(batch, xPos + (x * tileWidth), yPos + (y * tileHeight), tileWidth, tileHeight);
+                glyph.draw(batch, xPos + (x * tileWidth), yPos + (yy * tileHeight), tileWidth, tileHeight);
             }
         }
     }