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

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

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

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

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

pub fn set_rot(&mut self, rotation: i16)[src]

Set the rotation in degrees of the sprite. The rotation will attempt to match the nearest degrees of rotation divisor.

pub fn rot(&self) -> i16[src]

Get the pixel rotation as degrees.

Trait Implementations

impl Clone for Sprite[src]

impl Component for Sprite[src]

type Storage = VecStorage<Self>

Associated storage type for this component.

impl Debug for Sprite[src]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.