pub struct Sprite<'a, T: Into<f64> + Copy + AddAssign> {
pub texture: &'a Image,
pub coords: (T, T),
pub origin: (T, T),
}
Expand description
Use a Sprite for an object on your game which can move.
§Example
use wasm_game_lib::graphics::image::Image;
use wasm_game_lib::graphics::sprite::Sprite;
// load a texture from the web
let ferris_texture = Image::load("https://rustacean.net/assets/cuddlyferris.svg").await.unwrap();
// create a sprite
let ferris = Sprite::<u32>::new((0,0), &ferris_texture, (0,0));
// draw the sprite on a canvas
canvas.draw(&ferris);
Fields§
§texture: &'a Image
The texture of the Sprite
coords: (T, T)
Where the Sprite is located on the screen
origin: (T, T)
The point on the texture which is considered as the center of the Sprite. The coordinates of this point must be relative to the top-left corner of the object.
Implementations§
Source§impl<'a, T: Into<f64> + Copy + AddAssign> Sprite<'a, T>
impl<'a, T: Into<f64> + Copy + AddAssign> Sprite<'a, T>
Sourcepub fn new(coords: (T, T), texture: &Image, origin: (T, T)) -> Sprite<'_, T>
pub fn new(coords: (T, T), texture: &Image, origin: (T, T)) -> Sprite<'_, T>
Create a new Sprite.
§Example
use wasm_game_lib::graphics::image::Image;
use wasm_game_lib::graphics::sprite::Sprite;
// load a texture from the web
let ferris_texture = Image::load("https://rustacean.net/assets/cuddlyferris.svg").await.unwrap();
// create a sprite
let ferris = Sprite::<u32>::new((0,0), &ferris_texture, (0,0));
Sourcepub fn set_origin(&mut self, origin: (T, T))
pub fn set_origin(&mut self, origin: (T, T))
Set the origin. The origin is the point on the texture which is considered as the center of the Sprite. The coordinates of this point must be relative to the top-left corner of the object.
Sourcepub fn get_origin(&self) -> (T, T)
pub fn get_origin(&self) -> (T, T)
Return the origin. The origin is the point on the texture which is considered as the center of the Sprite. The coordinates of this point must be relative to the top-left corner of the object.
Sourcepub fn get_texture(&self) -> &Image
pub fn get_texture(&self) -> &Image
Return the texture.
Sourcepub fn set_texture(&mut self, texture: &'a Image)
pub fn set_texture(&mut self, texture: &'a Image)
Set the texture
Sourcepub fn set_coords(&mut self, coords: (T, T))
pub fn set_coords(&mut self, coords: (T, T))
Set the coordinates.
Sourcepub fn get_coords(&mut self) -> (T, T)
pub fn get_coords(&mut self) -> (T, T)
Return the coordinates.