Class TileLayerCollision

java.lang.Object
com.codename1.gaming.platformer.view.TileLayerCollision

public final class TileLayerCollision extends Object

Converts between a drawn com.codename1.gaming.level.TileLayer and the collision TileGrid the simulation reads.

A game painting its levels with an atlas keeps one table, "frame N of the sheet is solid, frame M is a one-way ledge", and derives the collision from the art with #toGrid; a game that writes Tile characters derives the art from the collision with #toLayer.

  • Method Details

    • toGrid

      public static TileGrid toGrid(TileLayer layer, int[] frameKinds)

      Builds the collision grid for a tile layer.

      Parameters
      • layer: the drawn layer
      • frameKinds: the Tile kind of each sheet frame; frames past the end and empty cells are Tile#EMPTY
      Returns

      a grid of the same size and tile size

    • toLayer

      public static TileLayer toLayer(TileGrid grid, SpriteSheet sheet, int[] kindFrames)

      Builds a tile layer that draws a collision grid.

      Parameters
      • grid: the grid
      • sheet: the tileset
      • kindFrames: the sheet frame for each Tile kind, indexed by kind; -1 or past the end draws nothing
      Returns

      the layer