[][src]Struct specs_blit::Sprite

pub struct Sprite { /* fields omitted */ }

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 2 pixels
    let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR], 1, Color::from_u32(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();

Methods

impl Sprite[src]

pub fn new(index: SpriteRef) -> Self[src]

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 2 pixels
    let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR], 1, Color::from_u32(MASK_COLOR));

    // Load the sprite and get a reference
    load(sprite)?
};

// Create a specs sprite from the image
let sprite = Sprite::new(sprite_ref);

pub fn set_pos(&mut self, x: i32, y: i32)[src]

Set the pixel position of where the sprite needs to be rendered.

pub fn pos(&self) -> (i32, i32)[src]

Get the pixel position as an (x, y) tuple of where the sprite will be rendered.

Trait Implementations

impl Component for Sprite[src]

type Storage = VecStorage<Self>

Associated storage type for this component.

Auto Trait Implementations

impl RefUnwindSafe for Sprite

impl Send for Sprite

impl Sync for Sprite

impl Unpin for Sprite

impl UnwindSafe for Sprite

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Event for T where
    T: Send + Sync + 'static, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Resource for T where
    T: Any + Send + Sync

impl<T> SetParameter for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.