pub struct Tilemap {
pub atlas: TextureId,
pub atlas_size: [u32; 2],
pub tile_size: [u32; 2],
pub width: u32,
pub height: u32,
pub origin: [f32; 2],
pub tiles: Vec<u16>,
pub layer: i16,
/* private fields */
}Expand description
Grid tilemap backed by an atlas. tiles indexes into the atlas left-to-right,
top-to-bottom; index 0 is treated as empty and skipped.
The map is split into square chunks (default 32x32 tiles). Each chunk caches its sprite
instances and only rebuilds them when a tile in it changes (or the origin moves). On
draw, chunks whose world-space AABB does not intersect the camera’s visible rectangle
are skipped, so a large map only touches the tiles actually on screen.
Fields§
§atlas: TextureId§atlas_size: [u32; 2]§tile_size: [u32; 2]§width: u32§height: u32§origin: [f32; 2]Origin in world space (top-left corner of cell (0,0)).
tiles: Vec<u16>§layer: i16Implementations§
Source§impl Tilemap
impl Tilemap
pub fn new( atlas: TextureId, atlas_size: [u32; 2], tile_size: [u32; 2], width: u32, height: u32, ) -> Tilemap
Sourcepub fn with_chunk_size(
atlas: TextureId,
atlas_size: [u32; 2],
tile_size: [u32; 2],
width: u32,
height: u32,
chunk_size: u32,
) -> Tilemap
pub fn with_chunk_size( atlas: TextureId, atlas_size: [u32; 2], tile_size: [u32; 2], width: u32, height: u32, chunk_size: u32, ) -> Tilemap
Like Tilemap::new but with an explicit chunk size (in tiles).
pub fn set(&mut self, x: u32, y: u32, tile: u16)
pub fn get(&self, x: u32, y: u32) -> u16
Sourcepub fn mark_all_dirty(&mut self)
pub fn mark_all_dirty(&mut self)
Mark every chunk dirty so the next Tilemap::draw rebuilds all instances. Call this
after mutating tiles, atlas_size, or tile_size directly (bypassing set).
Auto Trait Implementations§
impl Freeze for Tilemap
impl RefUnwindSafe for Tilemap
impl Send for Tilemap
impl Sync for Tilemap
impl Unpin for Tilemap
impl UnsafeUnpin for Tilemap
impl UnwindSafe for Tilemap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.