Struct simple_tilemap::Tileset
source · pub struct Tileset<C> { /* private fields */ }
Expand description
Tileset holds a collection of tiles stored as their pixel data.
Currently only supports RGBA 8 bits per channel.
Tiles are counted left-to-right then top-to-bottom.
Generic parameter C
is the container type, which should implement AsRef<[u8]>
.
You can use a simple Vec<u8>
/&[u8]
with RGBA data, Rc<[u8]>
/Arc<[u8]>
for cheap cloning
or e.g. image
’s ImageBuffer
.
Implementations§
source§impl<C> Tileset<C>
impl<C> Tileset<C>
sourcepub fn contains(&self, id: TileId) -> bool
pub fn contains(&self, id: TileId) -> bool
Whether id
is a valid tile id for this tileset.
Basically id < self.tile_count()
.
sourcepub fn tile_count(&self) -> u32
pub fn tile_count(&self) -> u32
Total amount of tiles in the tileset.
sourcepub fn options(&self) -> &TilesetOptions
pub fn options(&self) -> &TilesetOptions
Tileset options used when creating the tileset.
source§impl<C> Tileset<C>
impl<C> Tileset<C>
sourcepub fn new(
data: C,
width: u32,
height: u32,
opts: TilesetOptions
) -> Option<Self>
pub fn new( data: C, width: u32, height: u32, opts: TilesetOptions ) -> Option<Self>
Construct a new tileset.
width
and height
are data
’s size in pixels.
sourcepub fn get_tile_pos(&self, id: TileId) -> Option<(u32, u32)>
pub fn get_tile_pos(&self, id: TileId) -> Option<(u32, u32)>
Get the position of a tile in the tileset. Useful if you need to render a single tile.
sourcepub fn render_tile(
&self,
surface: &mut (impl BufferMut<Color> + ?Sized),
id: TileId,
offset_x: i32,
offset_y: i32,
opts: BlitOptions
)
pub fn render_tile( &self, surface: &mut (impl BufferMut<Color> + ?Sized), id: TileId, offset_x: i32, offset_y: i32, opts: BlitOptions )
Render a single tile from the tileset, accounting for the key color.
Trait Implementations§
Auto Trait Implementations§
impl<C> RefUnwindSafe for Tileset<C>where
C: RefUnwindSafe,
impl<C> Send for Tileset<C>where
C: Send,
impl<C> Sync for Tileset<C>where
C: Sync,
impl<C> Unpin for Tileset<C>where
C: Unpin,
impl<C> UnwindSafe for Tileset<C>where
C: UnwindSafe,
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