Struct sprite::Sprite
[−]
[src]
pub struct Sprite<I: ImageSize> { /* fields omitted */ }
A sprite is a texture with some properties.
Methods
impl<I: ImageSize> Sprite<I>
[src]
fn from_texture(texture: Rc<I>) -> Sprite<I>
Crate sprite from a texture
fn id(&self) -> Uuid
Get the sprite's id
fn get_visible(&self) -> bool
Whether or not the sprite is visible
fn set_visible(&mut self, visible: bool)
Set the sprite's visibility
fn get_anchor(&self) -> (Scalar, Scalar)
Get the sprite's anchor point
The value is normalized. Default value is 0.5, 0.5
fn set_anchor(&mut self, x: Scalar, y: Scalar)
Set the sprite's anchor point
fn get_position(&self) -> (Scalar, Scalar)
Get the sprite's position
fn set_position(&mut self, x: Scalar, y: Scalar)
Set the sprite's position
fn set_color(&mut self, r: f32, g: f32, b: f32)
Set the sprite's draw color (tint)
fn get_color(&self) -> (f32, f32, f32)
get the sprite's color.s
fn get_rotation(&self) -> Scalar
Get the sprite's rotation (in degree)
fn set_rotation(&mut self, deg: Scalar)
Set the sprite's rotation (in degree)
fn get_scale(&self) -> (Scalar, Scalar)
Get the sprite's scale
fn set_scale(&mut self, sx: Scalar, sy: Scalar)
Set the sprite's scale
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;
fn set_flip_x(&mut self, flip_x: bool)
Flip the sprite
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;
fn set_flip_y(&mut self, flip_y: bool)
Flip the sprite
fn get_opacity(&self) -> f32
Get the sprite's opacity
fn set_opacity(&mut self, opacity: f32)
Set the sprite's opacity
fn get_texture(&self) -> &Rc<I>
Get the sprite's texture
fn set_texture(&mut self, texture: Rc<I>)
Set the sprite's texture
fn add_child(&mut self, sprite: Sprite<I>) -> Uuid
Add a sprite as the child of this sprite, return the added sprite's id.
fn remove_child(&mut self, id: Uuid) -> Option<Sprite<I>>
Remove the child by id
from this sprite's children or grandchild
fn child(&self, id: Uuid) -> Option<&Sprite<I>>
Find the child by id
from this sprite's children or grandchild
fn child_mut(&mut self, id: Uuid) -> Option<&mut Sprite<I>>
Find the child by id
from this sprite's children or grandchild, mutability
fn children(&self) -> &Vec<Sprite<I>>
Get the sprite's children
fn draw<B: Graphics<Texture=I>>(&self, t: Matrix2d, b: &mut B)
Draw this sprite and its children
fn draw_tinted<B: Graphics<Texture=I>>(&self,
t: Matrix2d,
b: &mut B,
c: [f32; 3])
t: Matrix2d,
b: &mut B,
c: [f32; 3])
Draw this sprite and its children with color
fn bounding_box(&self) -> Rectangle
Get the sprite's bounding box