Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: Grid

[20:7] extends: FxObj

Wraps FXGL's Grid, a typed 2D array of Cell subclasses with cell neighbor queries. Most game code uses AStarGrid (chunk 4 pathfinding) rather than constructing a Grid directly, but for tile-map storage and simple cell queries Grid is the building block. The default constructor builds an AussomSimpleCell-typed grid of the given dimensions. Cell access (get / set) returns Cell wrappers; neighbor queries return a list of Cell wrappers.

Methods

  • Grid (int Width, int Height, int CellWidth = 0, int CellHeight = 0)

    Creates a new Grid of the given dimensions pre-populated with AussomSimpleCells.

    • @p Width is the column count.
    • @p Height is the row count.
  • _makeCell (X, Y)

    Internal — supplies cells to the Grid ctor's CellGenerator.

  • adopt (object Ajo)

    Wraps an existing Grid AussomJavaObject.

    • @p Ajo is an AussomJavaObject around an FXGL Grid.
    • @r A new wrapper.
  • getWidth ()

    Returns the grid width (column count).

    • @r An int.
  • getHeight ()

    Returns the grid height (row count).

    • @r An int.
  • getCellWidth ()

    Returns the per-cell width in pixels.

    • @r An int.
  • getCellHeight ()

    Returns the per-cell height in pixels.

    • @r An int.
  • isWithin (int X, int Y)

    Returns true if (X, Y) is inside the grid bounds.

    • @p X is the column.
    • @p Y is the row.
    • @r A bool.
  • get (int X, int Y)

    Returns the Cell at (X, Y).

    • @p X is the column.
    • @p Y is the row.
    • @r A Cell wrapper.
  • set (int X, int Y, object CellObj)

    Replaces the cell at (X, Y) with the provided Cell.

    • @p X is the column.
    • @p Y is the row.
    • @p CellObj is a Cell wrapper.
    • @r this object
  • getNeighbors (int X, int Y, string DirectionName = "FOUR_DIRECTIONS")

    Returns the list of neighboring cells around (X, Y). The NeighborDirection name controls whether to include diagonals.

    • @p X is the column.
    • @p Y is the row.
    • @p DirectionName is the NeighborDirection name (defaults to "FOUR_DIRECTIONS").
    • @r A list of Cell wrappers.
  • getCells ()

    Returns the list of all cells in the grid.

    • @r A list of Cell wrappers.
  • _opt (rawAjo)

  • getRight (int X, int Y)

    Returns the cell directly right of (X, Y), or null when off the grid.

    • @r A Cell wrapper or null.
  • getLeft (int X, int Y)

    Returns the cell directly left of (X, Y), or null.

    • @r A Cell wrapper or null.
  • getUp (int X, int Y)

    Returns the cell directly above (X, Y), or null.

    • @r A Cell wrapper or null.
  • getDown (int X, int Y)

    Returns the cell directly below (X, Y), or null.

    • @r A Cell wrapper or null.
  • getUpRight (int X, int Y)

    Returns the cell diagonally up-right of (X, Y), or null.

    • @r A Cell wrapper or null.
  • getUpLeft (int X, int Y)

    Returns the cell diagonally up-left of (X, Y), or null.

    • @r A Cell wrapper or null.
  • getDownRight (int X, int Y)

    Returns the cell diagonally down-right of (X, Y), or null.

    • @r A Cell wrapper or null.
  • getDownLeft (int X, int Y)

    Returns the cell diagonally down-left of (X, Y), or null.

    • @r A Cell wrapper or null.
  • getOptionalByPixels (double Px, double Py)

    Returns the cell at the given pixel coordinates (using cellWidth / cellHeight to map), or null when outside the grid.

    • @p Px is the pixel X.
    • @p Py is the pixel Y.
    • @r A Cell wrapper or null.
  • getOptional (int X, int Y)

    Returns the cell at (X, Y) safely, returning null when off the grid instead of throwing.

    • @r A Cell wrapper or null.
  • getRandomCell ()

    Returns a random cell from the grid.

    • @r A Cell wrapper.
  • forEach (callback Action)

    Calls Action(cell) for every cell in the grid.

    • @p Action is a callback (cell) -> void.
    • @r this object
  • getData ()

    Returns the raw 2D array of cells as an AussomJavaObject. Most callers prefer getCells or forEach; reach for getData only when iterating in 2D index space.

    • @r An AussomJavaObject around a 2D Cell array.