Struct Sprite

Source
pub struct Sprite<I: ImageSize> { /* private fields */ }
Expand description

A sprite is a texture with some properties.

Implementations§

Source§

impl<I: ImageSize> Sprite<I>

Source

pub fn from_texture(texture: Rc<I>) -> Sprite<I>

Crate sprite from a texture

Source

pub fn from_texture_rect(texture: Rc<I>, src_rect: SourceRectangle) -> Sprite<I>

Create sprite from a rectangle selection of a texture

Source

pub fn id(&self) -> Uuid

Get the sprite’s id

Source

pub fn get_visible(&self) -> bool

Whether or not the sprite is visible

Source

pub fn set_visible(&mut self, visible: bool)

Set the sprite’s visibility

Source

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)

Source

pub fn set_anchor(&mut self, x: Scalar, y: Scalar)

Set the sprite’s anchor point

Source

pub fn get_position(&self) -> (Scalar, Scalar)

Get the sprite’s position

Source

pub fn set_position(&mut self, x: Scalar, y: Scalar)

Set the sprite’s position

Source

pub fn set_color(&mut self, r: f32, g: f32, b: f32)

Set the sprite’s draw color (tint)

Source

pub fn get_color(&self) -> (f32, f32, f32)

get the sprite’s color.s

Source

pub fn get_rotation(&self) -> Scalar

Get the sprite’s rotation (in degree)

Source

pub fn set_rotation(&mut self, deg: Scalar)

Set the sprite’s rotation (in degree)

Source

pub fn get_scale(&self) -> (Scalar, Scalar)

Get the sprite’s scale

Source

pub fn set_scale(&mut self, sx: Scalar, sy: Scalar)

Set the sprite’s scale

Source

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;

Source

pub fn set_flip_x(&mut self, flip_x: bool)

Flip the sprite

Source

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;

Source

pub fn set_flip_y(&mut self, flip_y: bool)

Flip the sprite

Source

pub fn get_opacity(&self) -> f32

Get the sprite’s opacity

Source

pub fn set_opacity(&mut self, opacity: f32)

Set the sprite’s opacity

Source

pub fn get_src_rect(&self) -> Option<SourceRectangle>

Get the sprite’s source rectangle

Source

pub fn set_src_rect(&mut self, src_rect: SourceRectangle)

Set the sprite’s source rectangle

Source

pub fn get_texture(&self) -> &Rc<I>

Get the sprite’s texture

Source

pub fn set_texture(&mut self, texture: Rc<I>)

Set the sprite’s texture

Source

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.

Source

pub fn remove_child(&mut self, id: Uuid) -> Option<Sprite<I>>

Remove the child by id from this sprite’s children or grandchild

Source

pub fn child(&self, id: Uuid) -> Option<&Sprite<I>>

Find the child by id from this sprite’s children or grandchild

Source

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

Source

pub fn children(&self) -> &Vec<Sprite<I>>

Get the sprite’s children

Source

pub fn draw<B: Graphics<Texture = I>>(&self, t: Matrix2d, b: &mut B)

Draw this sprite and its children

Source

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

Source

pub fn bounding_box(&self) -> Rectangle

Get the sprite’s bounding box

Auto Trait Implementations§

§

impl<I> Freeze for Sprite<I>

§

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§

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