Skip to main content

Layer

Struct Layer 

Source
pub struct Layer {
    pub name: String,
    pub is_hidden: bool,
    pub sprites: Vec<Sprite>,
    pub tag_index: HashMap<String, usize>,
    pub render_index: Vec<(usize, i32)>,
    pub render_weight: i32,
}
Expand description

A Layer contains a set of Sprites stored in a vector. Sprites can be accessed via offset in the vector or by tag in the hashmap.

Fields§

§name: String§is_hidden: bool§sprites: Vec<Sprite>§tag_index: HashMap<String, usize>§render_index: Vec<(usize, i32)>§render_weight: i32

Implementations§

Source§

impl Layer

Source

pub fn new(name: &str) -> Self

Source

pub fn active(&mut self)

Source

pub fn deactive(&mut self)

Source

pub fn get_max_size(&self) -> PointU16

Source

pub fn add(&mut self, ts: Sprite, tag: &str)

Source

pub fn add_auto(&mut self, ts: Sprite)

Add sprite with auto-generated tag (for backward compatibility)

Source

pub fn get(&mut self, name: &str) -> &mut Sprite

Source

pub fn with_sprites<F, R>(&mut self, tags: &[&str], f: F) -> R
where F: FnOnce(&mut [&mut Sprite]) -> R,

Execute a closure with multiple sprites simultaneously

This method allows you to work with multiple sprites at once. Panics if any tags are duplicated.

§Safety

Uses unsafe code internally but ensures safety by checking for duplicate indices.

Source

pub fn get_immut(&self, name: &str) -> &Sprite

Source

pub fn set_weight(&mut self, name: &str, w: i32)

Source

pub fn set_hidden(&mut self, name: &str, hidden: bool)

Source

pub fn update_render_index(&mut self)

Source

pub fn render_all_to_buffer( &mut self, am: &mut AssetManager, buffer: &mut Buffer, )

Render all sprites to buffer by merging their content Scene::draw controls which layers should call this method

Trait Implementations§

Source§

impl Index<usize> for Layer

Implements Index and IndexMut protocol

Source§

type Output = Sprite

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Layer

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer

§

impl Sync for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> UnsafeAny for T
where T: Any,