Class IsoProjection
java.lang.Object
com.codename1.gaming.level.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.
-
Constructor Summary
ConstructorsConstructorDescriptionIsoProjection(float originX, float originY, float tileWidth, float tileHeight) -
Method Summary
Modifier and TypeMethodDescriptionfit(int n, int viewWidth, int viewHeight) Sizes the tiles and centers the board to fit annxngrid inside a view of the given pixel size, matching theBoardGameSamplefit (width-bound or height-bound, whichever is tighter, then centered).floatfloatfloatfloatint[]pick(int px, int py) Inverts a screen pixel to the nearest cell, returned as{row, col}.setOrigin(float originX, float originY) setTileSize(float tileWidth, float tileHeight) floattileCenterX(int row, int col) The screen x of the center of cell (row, col).floattileCenterY(int row, int col) The screen y of the center of cell (row, col).
-
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
-
getTileWidth
public float getTileWidth() -
getTileHeight
public float getTileHeight() -
setTileSize
-
fit
Sizes the tiles and centers the board to fit annxngrid inside a view of the given pixel size, matching theBoardGameSamplefit (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.
-