pub struct TileLayer { /* private fields */ }Expand description
A layer of tiles: a grid of square cells in the world, each empty or
showing a Tile of the layer’s TileSet.
Cell (0, 0) has its top-left corner at the origin; x grows to the
right and y down, as in a TileGrid of the collision crate. The
renderer draws a layer in chunks of TileLayer::CHUNK cells a side,
those that the view shows, and packs a chunk’s tiles again only after
one of them changes.
Implementations§
Source§impl TileLayer
impl TileLayer
Sourcepub fn new(tileset: TileSet, size: UVec2, tile_size: f32, origin: Vec2) -> Self
pub fn new(tileset: TileSet, size: UVec2, tile_size: f32, origin: Vec2) -> Self
A layer of size cells, columns by rows, all empty, of tile_size
world units a side, with its top-left corner at origin. A layer
with no columns or no rows draws nothing.
Cells are placed in f32, exactly up to 2^24 cells a side.
§Panics
If tile_size is not a finite number above 0, or the layer has more
cells than memory can count.
Sourcepub fn chunks(&self) -> UVec2
pub fn chunks(&self) -> UVec2
The number of chunks: columns by rows. The last of a row or column may be cut short by the layer’s edge.
Sourcepub fn get(&self, cell: IVec2) -> Option<Tile>
pub fn get(&self, cell: IVec2) -> Option<Tile>
The tile of cell: None if it is empty, or outside the layer.
Sourcepub fn set(&mut self, cell: IVec2, tile: Option<Tile>)
pub fn set(&mut self, cell: IVec2, tile: Option<Tile>)
Shows tile in cell, or empties it with None. The chunk that
holds the cell is packed again before it is next drawn, if this
changed it.
§Panics
If cell is outside the layer.
Sourcepub fn pack_chunk(&self, chunk: UVec2, out: &mut Vec<f32>) -> u32
pub fn pack_chunk(&self, chunk: UVec2, out: &mut Vec<f32>) -> u32
Appends the instances of the tiles of chunk chunk (its column and
row of chunks) to out, row by row, skipping empty cells:
TILE_INSTANCE_FLOATS floats each, as the renderer uploads them.
Returns how many there are; none for a chunk outside the layer.
The renderer does this for each chunk the view shows that changed since it last did. It is public so that it can be measured.