acron.tile_map

Tile-map runtime: render layers of placed tiles, collide, spawn scene tiles.

Consumes plain decoded data – TileCell / TileMapLayer (owned here) plus a tileset definition (acron.gdformat.tileset. TileSetDef, whose parser produces it) – and:

  • builds render geometry per layer – textured cards in the acron.canvas2d frame, one Geom per atlas texture, z_index draw order, nearest-neighbour filtering (build_layer_geometry()),

  • extracts collision as Bullet shapes for the plane-constrained 2D physics world: each tile physics polygon becomes a convex prism extruded along Acron +Y (build_collision_shapes()),

  • surfaces scene tiles for the game to instantiate (scene_tile_instances()).

The tileset data classes still live with their parser in acron.gdformat.tileset – this renderer migrates onto the acron scene format together with them (the tile pipeline moves as one).

TileCell(x, y, source_id, atlas, alternative)

One placed tile: map cell coords + its source/atlas/alternative ids.

TileMapLayer(index, name, z_index, enabled, ...)

One decoded layer_N of a TileMap node: metadata + its cells.

Global Functions

build_collision_shapes(layers, tileset, physics_layer: int = 0, scale=(1.0, 1.0), offset=(0.0, 0.0)) → list

Extract (BulletConvexHullShape, cell, one_way) triples for every physics polygon on every enabled layer’s tiles.

scale/offset are the TileMap NODE’s own transform (Godot scales tile collision with the node) – pass them so scaled tilemap instances collide where they render.

Polygon points are tile-local pixels centred on the cell (y down); each becomes a convex prism spanning Y = +-PLANE_HALF_THICK in the canvas frame at its world position (baked into the vertices – attach them all to one static body at the origin).

build_layer_geometry(layer, tileset, parent, base_z_index: int = 0)

Build one layer’s tiles as textured cards under parent.

Returns the layer’s NodePath. Cards live in the canvas2d frame: a cell (cx, cy) covers Godot pixels [cx*ts, (cx+1)*ts) x [cy*ts, (cy+1)*ts) -> Acron X right, Z = -y. Flip/transpose bits of the alternative id are applied to the UVs. Animated tiles show their first frame (drive further frames game-side if needed). Tiles carrying a Godot material flatten into their own group node, tagged tile_material with :attr:`acron.tileset.TileDef.material` – games find them with layer_np.find_all_matches("**/=tile_material") and apply shaders.

scene_tile_instances(layers, tileset)

Yield (scene_res_path, godot_x_px, godot_y_px, cell) for every scene tile (TileSetScenesCollectionSource) – the game instantiates its own ported entity there. Position is the cell centre in Godot pixels.

Scene tiles store the scene index in the cell’s ALTERNATIVE id (their atlas coords are (0, 0)) – verified against real level data.