pub struct Sprite { /* private fields */ }
Expand description
Specs component representing a sprite that can be drawn.
use blit::{BlitBuffer, Color};
use specs::prelude::*;
use specs_blit::{load, Sprite};
const MASK_COLOR: u32 = 0xFF00FF;
// Setup the specs world
let mut world = World::new();
// Load the blit components into the world
world.register::<Sprite>();
let sprite_ref = {
// Create a sprite of 4 pixels
let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR, 0, 0], 2, MASK_COLOR);
// Load the sprite and get a reference
load(sprite)?
};
// Create a new sprite entity in the ECS system
world.create_entity()
.with(Sprite::new(sprite_ref))
.build();
Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn new(sprite_reference: SpriteRef) -> Self
pub fn new(sprite_reference: SpriteRef) -> Self
Instantiate a new sprite from a loaded sprite index.
use blit::{BlitBuffer, Color};
use specs_blit::{load, Sprite};
const MASK_COLOR: u32 = 0xFF00FF;
let sprite_ref = {
// Create a sprite of 4 pixels
let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR, 0, 0], 2, MASK_COLOR);
// Load the sprite and get a reference
load(sprite)?
};
// Create a specs sprite from the image
let sprite = Sprite::new(sprite_ref);
Sourcepub fn set_pos(&mut self, x: i32, y: i32)
pub fn set_pos(&mut self, x: i32, y: i32)
Set the pixel position of where the sprite needs to be rendered.
Sourcepub fn pos(&self) -> (i32, i32)
pub fn pos(&self) -> (i32, i32)
Get the pixel position as an (x, y) tuple of where the sprite will be rendered.
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<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
Mutably borrows from an owned value. Read more