pub struct Sprite<I: ImageSize> { /* private fields */ }
Expand description
A sprite is a texture with some properties.
Implementations
sourceimpl<I: ImageSize> Sprite<I>
impl<I: ImageSize> Sprite<I>
sourcepub fn from_texture(texture: Rc<I>) -> Sprite<I>
pub fn from_texture(texture: Rc<I>) -> Sprite<I>
Crate sprite from a texture
sourcepub fn from_texture_rect(texture: Rc<I>, src_rect: SourceRectangle) -> Sprite<I>
pub fn from_texture_rect(texture: Rc<I>, src_rect: SourceRectangle) -> Sprite<I>
Create sprite from a rectangle selection of a texture
sourcepub fn get_visible(&self) -> bool
pub fn get_visible(&self) -> bool
Whether or not the sprite is visible
sourcepub fn set_visible(&mut self, visible: bool)
pub fn set_visible(&mut self, visible: bool)
Set the sprite’s visibility
sourcepub fn get_anchor(&self) -> (Scalar, Scalar)
pub fn get_anchor(&self) -> (Scalar, Scalar)
Get the sprite’s anchor point
The value is normalized. Default value is [0.5, 0.5] (the center of texture)
sourcepub fn set_anchor(&mut self, x: Scalar, y: Scalar)
pub fn set_anchor(&mut self, x: Scalar, y: Scalar)
Set the sprite’s anchor point
sourcepub fn set_position(&mut self, x: Scalar, y: Scalar)
pub fn set_position(&mut self, x: Scalar, y: Scalar)
Set the sprite’s position
sourcepub fn get_rotation(&self) -> Scalar
pub fn get_rotation(&self) -> Scalar
Get the sprite’s rotation (in degree)
sourcepub fn set_rotation(&mut self, deg: Scalar)
pub fn set_rotation(&mut self, deg: Scalar)
Set the sprite’s rotation (in degree)
sourcepub fn get_flip_x(&self) -> bool
pub fn get_flip_x(&self) -> bool
Whether or not the sprite is flipped horizontally.
It only flips the texture of the sprite, and not the texture of the sprite’s children.
Also, flipping the texture doesn’t alter the anchor
.
If you want to flip the anchor
too,
and/or to flip the children too use: sprite.scale.x *= -1;
sourcepub fn set_flip_x(&mut self, flip_x: bool)
pub fn set_flip_x(&mut self, flip_x: bool)
Flip the sprite
sourcepub fn get_flip_y(&self) -> bool
pub fn get_flip_y(&self) -> bool
Whether or not the sprite is flipped vertically.
It only flips the texture of the sprite, and not the texture of the sprite’s children.
Also, flipping the texture doesn’t alter the anchor
.
If you want to flip the anchor
too,
and/or to flip the children too use: sprite.scale.y *= -1;
sourcepub fn set_flip_y(&mut self, flip_y: bool)
pub fn set_flip_y(&mut self, flip_y: bool)
Flip the sprite
sourcepub fn get_opacity(&self) -> f32
pub fn get_opacity(&self) -> f32
Get the sprite’s opacity
sourcepub fn set_opacity(&mut self, opacity: f32)
pub fn set_opacity(&mut self, opacity: f32)
Set the sprite’s opacity
sourcepub fn get_src_rect(&self) -> Option<SourceRectangle>
pub fn get_src_rect(&self) -> Option<SourceRectangle>
Get the sprite’s source rectangle
sourcepub fn set_src_rect(&mut self, src_rect: SourceRectangle)
pub fn set_src_rect(&mut self, src_rect: SourceRectangle)
Set the sprite’s source rectangle
sourcepub fn get_texture(&self) -> &Rc<I>
pub fn get_texture(&self) -> &Rc<I>
Get the sprite’s texture
sourcepub fn set_texture(&mut self, texture: Rc<I>)
pub fn set_texture(&mut self, texture: Rc<I>)
Set the sprite’s texture
sourcepub fn add_child(&mut self, sprite: Sprite<I>) -> Uuid
pub fn add_child(&mut self, sprite: Sprite<I>) -> Uuid
Add a sprite as the child of this sprite, return the added sprite’s id.
sourcepub fn remove_child(&mut self, id: Uuid) -> Option<Sprite<I>>
pub fn remove_child(&mut self, id: Uuid) -> Option<Sprite<I>>
Remove the child by id
from this sprite’s children or grandchild
sourcepub fn child(&self, id: Uuid) -> Option<&Sprite<I>>
pub fn child(&self, id: Uuid) -> Option<&Sprite<I>>
Find the child by id
from this sprite’s children or grandchild
sourcepub fn child_mut(&mut self, id: Uuid) -> Option<&mut Sprite<I>>
pub fn child_mut(&mut self, id: Uuid) -> Option<&mut Sprite<I>>
Find the child by id
from this sprite’s children or grandchild, mutability
sourcepub fn draw<B: Graphics<Texture = I>>(&self, t: Matrix2d, b: &mut B)
pub fn draw<B: Graphics<Texture = I>>(&self, t: Matrix2d, b: &mut B)
Draw this sprite and its children
sourcepub fn draw_tinted<B: Graphics<Texture = I>>(
&self,
t: Matrix2d,
b: &mut B,
c: [f32; 3]
)
pub fn draw_tinted<B: Graphics<Texture = I>>(
&self,
t: Matrix2d,
b: &mut B,
c: [f32; 3]
)
Draw this sprite and its children with color
sourcepub fn bounding_box(&self) -> Rectangle
pub fn bounding_box(&self) -> Rectangle
Get the sprite’s bounding box
Auto Trait Implementations
impl<I> RefUnwindSafe for Sprite<I> where
I: RefUnwindSafe,
impl<I> !Send for Sprite<I>
impl<I> !Sync for Sprite<I>
impl<I> Unpin for Sprite<I>
impl<I> UnwindSafe for Sprite<I> where
I: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more