Struct agb::display::object::TagMap

source ·
pub struct TagMap { /* private fields */ }
Expand description

Stores aseprite tags. Can be used to refer to animation sequences by name.

const GRAPHICS: &Graphics = include_aseprite!(
    "examples/gfx/boss.aseprite",
    "examples/gfx/objects.aseprite"
);

const EMU_WALK: &Tag = GRAPHICS.tags().get("emu-walk");

This being the whole animation associated with the walk sequence of the emu. See Tag for details on how to use this.

Implementations§

source§

impl TagMap

source

pub const fn get(&'static self, tag: &str) -> &'static Tag

Gets a tag associated with the name. A tag in aseprite refers to a sequence of sprites with some metadata for how to animate it. You should call this in a constant context so it is evaluated at compile time. It is inefficient to call this elsewhere.

const GRAPHICS: &Graphics = include_aseprite!(
    "examples/gfx/boss.aseprite",
    "examples/gfx/objects.aseprite"
);

const EMU_WALK: &Tag = GRAPHICS.tags().get("emu-walk");

See Tag for more details.

source

pub fn values(&self) -> impl Iterator<Item = &'static Tag>

Takes an iterator over all the tags in the map. Not generally useful.

Examples found in repository?
examples/sprites.rs (line 82)
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
fn all_tags(gfx: &OamManaged) {
    let mut input = agb::input::ButtonController::new();
    let mut objs = Vec::new();

    for (i, v) in TAG_MAP.values().enumerate() {
        let x = (i % 7) as i32;
        let y = (i / 7) as i32;
        let sprite = v.sprite(0);
        let (size_x, size_y) = sprite.size().to_width_height();
        let (size_x, size_y) = (size_x as i32, size_y as i32);
        let mut obj = gfx.object_sprite(sprite);
        obj.show();
        obj.set_position((x * 32 + 16 - size_x / 2, y * 32 + 16 - size_y / 2).into());
        objs.push((obj, v));
    }

    let mut count = 0;
    let mut image = 0;

    let vblank = agb::interrupt::VBlank::get();

    loop {
        vblank.wait_for_vblank();

        input.update();

        if input.is_just_pressed(agb::input::Button::A) {
            break;
        }

        count += 1;

        if count % 5 == 0 {
            image += 1;
            for (obj, tag) in objs.iter_mut() {
                obj.set_sprite(gfx.sprite(tag.animation_sprite(image)));
            }
            gfx.commit();
        }
    }
}

Auto Trait Implementations§

§

impl RefUnwindSafe for TagMap

§

impl !Send for TagMap

§

impl !Sync for TagMap

§

impl Unpin for TagMap

§

impl UnwindSafe for TagMap

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.