public class IsoProjection
- Object
- IsoProjection
Maps between board cells (row, column) and screen pixels for the 2:1 isometric “diamond” layout used by board / strategy games.
This is the projection the BoardGameSample hand-rolled, promoted to a reusable
piece so a board-mode GameLevel and its editor share one source of truth. A tile
is #getTileWidth() x #getTileHeight() pixels (height is conventionally half the
width), and (#getOriginX(), #getOriginY()) is the screen position of cell (0,0)’s
center. #tileCenterX(int, int) / #tileCenterY(int, int) go cell -> screen and
#pick(int, int) inverts screen -> cell.
Constructors
public IsoProjection() | |
public IsoProjection(float originX, float originY, float tileWidth, float tileHeight) |
Methods
public float getOriginX() | |
public float getOriginY() | |
public IsoProjection setOrigin(float originX, float originY) | |
public float getTileWidth() | |
public float getTileHeight() | |
public IsoProjection setTileSize(float tileWidth, float tileHeight) | |
public IsoProjection fit(int n, int viewWidth, int viewHeight) | Sizes the tiles and centers the board to fit an n x n grid inside a view of the given pixel size, matching the BoardGameSample fit (width-bound or height-bound, whichever is tighter, then centered). |
public float tileCenterX(int row, int col) | The screen x of the center of cell (row, col). |
public float tileCenterY(int row, int col) | The screen y of the center of cell (row, col). |
public int[] pick(int px, int py) | Inverts a screen pixel to the nearest cell, returned as {row, col}. |
Inherited methods
Constructor details
IsoProjection
public IsoProjection()IsoProjection
public IsoProjection(float originX, float originY, float tileWidth, float tileHeight)Method details
getOriginX
public float getOriginX()getOriginY
public float getOriginY()setOrigin
public IsoProjection setOrigin(float originX, float originY)getTileWidth
public float getTileWidth()getTileHeight
public float getTileHeight()setTileSize
public IsoProjection setTileSize(float tileWidth, float tileHeight)fit
public IsoProjection fit(int n, int viewWidth, int viewHeight)Sizes the tiles and centers the board to fit an
n x n grid inside a view of
the given pixel size, matching the BoardGameSample fit (width-bound or
height-bound, whichever is tighter, then centered).tileCenterX
public float tileCenterX(int row, int col)The screen x of the center of cell (row, col).
tileCenterY
public float tileCenterY(int row, int col)The screen y of the center of cell (row, col).
pick
public int[] pick(int px, int py)Inverts a screen pixel to the nearest cell, returned as
{row, col}. The result
is not clamped to any board size – callers validate the range.