Krotox Engine › Docs › Krotox Manual › 2D Content

Tilemaps, Tile Palette & level generation

Building 2D levels: grids and tilemaps, painting with the Tile Palette, rule tiles and auto-tiling, tilemap colliders, generating layouts procedurally, and placing props with the Prefab Palette.

Most 2D levels are built from tiles: small square (or diamond, or hexagonal) images placed on a grid. Krotox stores tiles in chunks, draws them in batches and can turn them into colliders automatically.

The pieces

ComponentRole
GridDefines the cell geometry. Put it on a parent entity.
TilemapHolds the tiles of one layer and the tile set they come from. Usually a child of the Grid.
Tilemap RendererDraws the tilemap.
Tilemap Collider 2DGenerates collision from the painted tiles.
Composite Collider 2DMerges tile colliders into a few smooth outlines or polygons.

A typical level looks like this:

Level            (Grid)
├── Background   (Tilemap, Tilemap Renderer)                       - no collision
├── Ground       (Tilemap, Tilemap Renderer, Tilemap Collider 2D,
│                 Composite Collider 2D, Rigidbody 2D: Static)     - solid
└── Decoration   (Tilemap, Tilemap Renderer)                       - drawn on top

Use separate tilemaps for layers that draw at different depths or behave differently, and set each one's Sorting Layer and Order in Layer.

Grid

FieldDefaultMeaning
LayoutRectangleCell geometry: Rectangle, Isometric Diamond, Isometric Staggered, Hexagon Pointy Top or Hexagon Flat Top.
Cell Size—Size of one cell in world units.
Cell Gap0Space between cells.
SwizzleXYZAxis order, for unusual orientations. Leave it at XYZ for 2D.

Tilemap

FieldDefaultMeaning
Tile SetnoneThe texture the tiles are cut from.
Cell Size16, 16Size of one tile on the texture, in pixels.
Sprite Size1, 1Cells per tile.
Gap Size0, 0Pixel spacing between tiles on the texture.
Color TintwhiteTint applied to every tile.
Sorting Layer, Order in LayerDefault, 0Draw order.
Mask InteractionNoneClip the tilemap with a Sprite Mask.

Tiles are stored in 32×32 chunks, so a huge, mostly empty map costs nothing for the empty parts.

Tilemap Renderer

FieldDefaultMeaning
ModeChunkChunk draws each chunk as one batch (fast, the right choice almost always). Individual draws tiles one by one, so they can sort against other sprites.
MaterialnoneOptional material.

Painting with the Tile Palette

Open View ▸ Tile Palette, select the tilemap you want to paint into, and pick a tile from the palette.

ToolKeyWhat it does
Select—Normal picking; no painting.
PaintBPaint the chosen tile under the cursor; drag to paint a stroke.
LineLA straight row of tiles from where you press to where you release.
Box fillUFill a rectangle.
Flood fillGFill a connected area.
EyedropperIPick up the tile under the cursor.
EraseDRemove tiles.

The Viewport overlays the cell grid in the grid's own geometry (rectangular, isometric or hexagonal), the hovered cell, the box-fill rectangle, 32×32 chunk boundaries, and the traced collision outline with arrows showing its winding.

Flood fill stays inside the painted area plus a margin, so filling an empty cell on an empty map cannot spread forever. A box fill larger than 20,000 cells does nothing.

Rule tiles and auto-tiling

A rule tile picks the right sprite for each cell from its eight neighbours: corners, edges, inner corners and ends, so you paint "ground" and the edges take care of themselves.

Turn on Auto-Tiling in the Tile Palette and paint with a rule tile. Every stamp and erase re-resolves the cell and its eight neighbours as you go. Undo also restores the neighbours it changed, so the edges always match the shape on screen.

Collision from tiles

  1. Add a Tilemap Collider 2D to the tilemap. Each painted tile gets a collider shape.
  2. Add a Composite Collider 2D and leave the tilemap collider's Used By Composite on. The tile shapes merge into a few long outlines, which is cheaper and stops characters snagging on the seams between tiles.
  3. Add a Rigidbody 2D set to Static.
Tilemap Collider 2D fieldDefaultMeaning
Used By CompositeonHand the shapes to the Composite Collider instead of using them directly.
Density, Friction, Restitution1, 0.5, 0Material, as on other colliders.
Is SensoroffMake the whole tilemap a trigger (water, hazards).
Category Bits, Mask Bits, Use Layer Collision Matrix—Collision filtering.
Composite Collider 2D fieldDefaultMeaning
Geometry TypeOutlinesOutlines makes hollow edge loops (best for terrain). Polygons makes solid shapes.
Collinear Tolerance0.01Merges nearly straight runs of points.
Generate Inner HolesonKeep holes inside shapes.

Generating levels: the Level Generator

View ▸ Level Generator builds a layout from an algorithm and a seed, previews it live and bakes it into the selected tilemap. The same seed always gives the same layout.

AlgorithmProducesUse it for
Cellular AutomataOrganic cavernsCaves, mines, asteroid fields.
BSP DungeonRectangular rooms joined by corridorsRoguelikes and top-down dungeons.
Drunkard's WalkMeandering tunnelsCatacombs, irregular warrens.
Chunk StitcherA platformer level from hand-made chunksSide-scrollers. Connected from entrance to exit by construction.
Galton BoardA staggered peg layoutPlinko and drop-style boards; every bin is reachable.
Wave Function CollapseRooms and corridors learned from a sampleLayouts that should look hand-made rather than noisy.
Noise FieldTerrain cut at a thresholdOverworlds, elevation, ore density, biome masks.

Reading the preview. Under the preview a connectivity readout shows the number of floor regions, total floor cells and the largest region. A level the player can fully explore reports a single region. More than one means pockets the player cannot reach. For caves, leave Connect Isolated Pockets on: it tunnels every separate cavern into the main one. The same option is useful for Wave Function Collapse and Noise Field, whose output is often in separate pieces.

Spawn rules place the player start, the exit, enemies per room and collectibles, shown as coloured markers. Drop a prefab onto a slot and baking instantiates it.

Step debugger. Tick Step through generation to run the real generator cut short at a chosen stage (for caves: the raw noise, then each smoothing pass). Baking is disabled while a partial result is shown, because an undecided cell is neither floor nor wall.

Bake to Active Tilemap stamps the preview into the tilemap, optionally resolving rule tiles, as a single undo step.

The generator runs the same KrotoxEngine.PCG library your game can call at run time, so the preview is exactly what that seed builds in game. It needs the scripting runtime, so a project must be open.

Validation Suite runs the generator test suite in place (several hundred layouts in a second or two): determinism, solvability, connectivity and timing. Run it after changing a generator.

To generate levels from code at run time, see Tilemap, Grid & level generation API.

Placing props: the Prefab Palette

View ▸ Prefab Palette places prefab instances by hand or sprays them with a brush.

ToolWhat it does
SelectNormal picking.
PlaceOne instance per click.
ScatterSprays instances while you drag.
EraseRemoves instances of the selected prefab under the brush, and nothing else.

A ghost marker shows exactly where the next instance will land. A whole drag is one undo step, and redo restores the same random variation instead of re-rolling it.

Moving platforms, doors and flippers

For things that move along a path or swing on a hinge, use the Motion Path component (see physics gameplay components). In one of its rotating modes, a magenta pivot handle appears on the entity: drag it to place the hinge, holding Ctrl to snap to eighths of a unit. The orange Angle Snap Gizmo (View ▸ Angle Snap Gizmo) rotates in fixed steps (15° by default); hold Shift for a free angle.