pub struct Sprite { /* private fields */ }
Expand description
A sprite used for drawing on a Layer
.
Sprites are created from spritesheets containing one or more frames. To determine frame
dimensions, Sprite::from_file()
expects sprite sheet file names to
follow a specific pattern. (Future versions will add more configurable means to load sprites.)
Implementations§
Source§impl<'a> Sprite
impl<'a> Sprite
Sourcepub fn from_file(context: &RenderContext, file: &str) -> Result<Self>
pub fn from_file(context: &RenderContext, file: &str) -> Result<Self>
Creates a new sprite texture. Given filename is expected to end
on _
Sourcepub fn from_data(
context: &RenderContext,
data: &[u8],
parameters: &SpriteParameters,
) -> Result<Self>
pub fn from_data( context: &RenderContext, data: &[u8], parameters: &SpriteParameters, ) -> Result<Self>
Creates a new sprite texture.
Sourcepub fn draw<T>(
&self,
layer: &Layer,
frame_id: u32,
position: T,
color: Color,
) -> &Self
pub fn draw<T>( &self, layer: &Layer, frame_id: u32, position: T, color: Color, ) -> &Self
Draws a sprite onto the given layer.
Sourcepub fn draw_transformed<T, U>(
&self,
layer: &Layer,
frame_id: u32,
position: T,
color: Color,
rotation: f32,
scale: U,
) -> &Self
pub fn draw_transformed<T, U>( &self, layer: &Layer, frame_id: u32, position: T, color: Color, rotation: f32, scale: U, ) -> &Self
Draws a sprite onto the given layer and applies given color, rotation and scaling.
Sourcepub fn set_anchor(&mut self, anchor: (f32, f32)) -> &Self
pub fn set_anchor(&mut self, anchor: (f32, f32)) -> &Self
Defines the sprite origin. Defaults to (0.5, 0.5), meaning that the center of the
sprite would be drawn at the coordinates given to Sprite::draw()
. Likewise, (0.0, 0.0)
would mean that the sprite’s top left corner would be drawn at the given coordinates.
Sourcepub fn num_frames(&self) -> u32
pub fn num_frames(&self) -> u32
Returns the number of frames of the sprite.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sprite
impl RefUnwindSafe for Sprite
impl Send for Sprite
impl Sync for Sprite
impl Unpin for Sprite
impl UnwindSafe for Sprite
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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>
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>
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)
&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)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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