pub struct Tilemap {
pub width: u16,
pub height: u16,
pub entries: Vec<TilemapEntry>,
}Expand description
A two-dimensional tilemap using TilemapEntry instead of raw byte
indices.
Unlike the classic GB TileMap (a flat Vec<u8> of tile indices),
this tilemap carries per-tile metadata and supports arbitrary widths
and heights.
Fields§
§width: u16Number of tiles horizontally.
height: u16Number of tiles vertically.
entries: Vec<TilemapEntry>Row-major tile entries. entries[y * width as usize + x].
Implementations§
Source§impl Tilemap
impl Tilemap
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Creates a new tilemap filled with default entries (tile_id = 0, no flips, no collision/animation overrides).
§Panics
Panics if width or height is 0.
Sourcepub fn from_gb_tilemap(data: &[u8], width: u16, height: u16) -> Self
pub fn from_gb_tilemap(data: &[u8], width: u16, height: u16) -> Self
Converts a classic Game Boy tilemap (flat &[u8] of tile indices)
into a Tilemap of TilemapEntrys.
Each byte in data becomes a TilemapEntry with that byte as
tile_id and all other fields set to their defaults.
§Panics
Panics if data.len() is less than width * height.
Sourcepub fn get(&self, x: u16, y: u16) -> Option<&TilemapEntry>
pub fn get(&self, x: u16, y: u16) -> Option<&TilemapEntry>
Returns a reference to the tile entry at (x, y), or None if
out of bounds.
Sourcepub fn get_mut(&mut self, x: u16, y: u16) -> Option<&mut TilemapEntry>
pub fn get_mut(&mut self, x: u16, y: u16) -> Option<&mut TilemapEntry>
Returns a mutable reference to the tile entry at (x, y), or
None if out of bounds.
Sourcepub fn set(&mut self, x: u16, y: u16, entry: TilemapEntry)
pub fn set(&mut self, x: u16, y: u16, entry: TilemapEntry)
Sets the tile entry at (x, y). Silently does nothing if out of bounds.