The 2D layer · function
drawTilemap
Draw the tiles the view can see. Returns how many that was.
Explained in Sprites and tilemaps.
function drawTilemap(batch: SpriteBatch, map: Tilemap, sheet: SpriteSheet, view: ViewRect, tint: ArrayLike<number> | null): numberimport { drawTilemap } from '@driftengine/ui2d';Parameters
| Parameter | Type | Description |
|---|---|---|
batch | SpriteBatch | |
map | Tilemap | |
sheet | SpriteSheet | |
view | ViewRect | |
tint | ArrayLike<number> | null |
In depth
The cost is the view rather than the map, which is the whole reason this is a function and not a loop the caller writes: the visible span is arithmetic on four numbers, so a map of a million cells costs the few hundred on screen. A walk over every cell testing each against the view would draw exactly the same picture and be unusable at the size a tilemap exists for.
Which way the rows run is the affine's business, not this function's. A cell's corner is
y + row * tileHeight, so in screen space — where y counts down — row 0 is the top row, and in a
2D world — where y counts up — it is the bottom. That is the same rule SpritePlacement states
about its own corner, and having one rule rather than a flag is what keeps the two agreeing.