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>

source

pub fn contains(&self, id: TileId) -> bool

Whether id is a valid tile id for this tileset.

Basically id < self.tile_count().

source

pub fn tile_count(&self) -> u32

Total amount of tiles in the tileset.

source

pub fn options(&self) -> &TilesetOptions

Tileset options used when creating the tileset.

source§

impl<C> Tileset<C>
where C: AsRef<[u8]>,

source

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.

source

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.

source

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§

source§

impl<C> Buffer<RGBA<u8>> for Tileset<C>
where C: AsRef<[u8]>,

source§

fn width(&self) -> u32

Buffer width
source§

fn height(&self) -> u32

Buffer height
source§

fn get(&self, x: u32, y: u32) -> &Color

Get a value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.
source§

impl<C> BufferMut<RGBA<u8>> for Tileset<C>
where C: AsRef<[u8]> + AsMut<[u8]>,

source§

fn get_mut(&mut self, x: u32, y: u32) -> &mut Color

Get a mutable value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.
source§

impl<C: Clone> Clone for Tileset<C>

source§

fn clone(&self) -> Tileset<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug> Debug for Tileset<C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.