Krotox Engine › Docs › Krotox Manual › 2D Content
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.
| Component | Role |
|---|---|
| Grid | Defines the cell geometry. Put it on a parent entity. |
| Tilemap | Holds the tiles of one layer and the tile set they come from. Usually a child of the Grid. |
| Tilemap Renderer | Draws the tilemap. |
| Tilemap Collider 2D | Generates collision from the painted tiles. |
| Composite Collider 2D | Merges 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.
| Field | Default | Meaning |
|---|---|---|
Layout | Rectangle | Cell geometry: Rectangle, Isometric Diamond, Isometric Staggered, Hexagon Pointy Top or Hexagon Flat Top. |
Cell Size | — | Size of one cell in world units. |
Cell Gap | 0 | Space between cells. |
Swizzle | XYZ | Axis order, for unusual orientations. Leave it at XYZ for 2D. |
| Field | Default | Meaning |
|---|---|---|
Tile Set | none | The texture the tiles are cut from. |
Cell Size | 16, 16 | Size of one tile on the texture, in pixels. |
Sprite Size | 1, 1 | Cells per tile. |
Gap Size | 0, 0 | Pixel spacing between tiles on the texture. |
Color Tint | white | Tint applied to every tile. |
Sorting Layer, Order in Layer | Default, 0 | Draw order. |
Mask Interaction | None | Clip 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.
| Field | Default | Meaning |
|---|---|---|
Mode | Chunk | Chunk 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. |
Material | none | Optional material. |
Open View ▸ Tile Palette, select the tilemap you want to paint into, and pick a tile from the palette.
| Tool | Key | What it does |
|---|---|---|
| Select | — | Normal picking; no painting. |
| Paint | B | Paint the chosen tile under the cursor; drag to paint a stroke. |
| Line | L | A straight row of tiles from where you press to where you release. |
| Box fill | U | Fill a rectangle. |
| Flood fill | G | Fill a connected area. |
| Eyedropper | I | Pick up the tile under the cursor. |
| Erase | D | Remove tiles. |
X and Y flip the brush tile, and R rotates it 90°.Escape leaves paint mode without closing the palette.Ctrl+Z undoes a whole stroke, box fill or flood fill at once.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.
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.
| Tilemap Collider 2D field | Default | Meaning |
|---|---|---|
Used By Composite | on | Hand the shapes to the Composite Collider instead of using them directly. |
Density, Friction, Restitution | 1, 0.5, 0 | Material, as on other colliders. |
Is Sensor | off | Make the whole tilemap a trigger (water, hazards). |
Category Bits, Mask Bits, Use Layer Collision Matrix | — | Collision filtering. |
| Composite Collider 2D field | Default | Meaning |
|---|---|---|
Geometry Type | Outlines | Outlines makes hollow edge loops (best for terrain). Polygons makes solid shapes. |
Collinear Tolerance | 0.01 | Merges nearly straight runs of points. |
Generate Inner Holes | on | Keep holes inside shapes. |
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.
| Algorithm | Produces | Use it for |
|---|---|---|
| Cellular Automata | Organic caverns | Caves, mines, asteroid fields. |
| BSP Dungeon | Rectangular rooms joined by corridors | Roguelikes and top-down dungeons. |
| Drunkard's Walk | Meandering tunnels | Catacombs, irregular warrens. |
| Chunk Stitcher | A platformer level from hand-made chunks | Side-scrollers. Connected from entrance to exit by construction. |
| Galton Board | A staggered peg layout | Plinko and drop-style boards; every bin is reachable. |
| Wave Function Collapse | Rooms and corridors learned from a sample | Layouts that should look hand-made rather than noisy. |
| Noise Field | Terrain cut at a threshold | Overworlds, 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.
View ▸ Prefab Palette places prefab instances by hand or sprays them with a brush.
| Tool | What it does |
|---|---|
| Select | Normal picking. |
| Place | One instance per click. |
| Scatter | Sprays instances while you drag. |
| Erase | Removes instances of the selected prefab under the brush, and nothing else. |
V to snap to the nearest tile corner or sprite corner, in the grid's real geometry (isometric and hexagonal too).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.
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.