include_background_gfx!() { /* proc-macro */ }
Expand description

This macro is used to convert a png or bmp into a format usable by the Game Boy Advance.

Suppose you have a file in examples/water_tiles.png which contains some tiles you’d like to use.

You import them using:

#![no_std]
#![no_main]
agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");

This will generate something along the lines of the following:

// module name comes from the first argument, name of the constant from the arrow
mod water_tiles {
    pub const tiles = /* ... */;
}

And tiles will be an instance of TileData

You can import multiple files at once, and the palette data will be combined so they can all be visible.

Examples

Assume the tiles are loaded as above

In src/main.rs:

#![no_std]
#![no_main]
use agb::{
    display::{
        tiled::{RegularBackgroundSize, TileFormat, TileSet, TileSetting, Tiled0, TiledMap, VRamManager},
        Priority,
    },
    include_background_gfx,
};

agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");

let tileset = TileSet::new(water_tiles::tiles.tiles, TileFormat::FourBpp);

vram.set_background_palettes(water_tiles::PALETTES);

let mut bg = gfx.background(Priority::P0, RegularBackgroundSize::Background32x32, TileFormat::FourBpp);

for y in 0..20u16 {
    for x in 0..30u16 {
        bg.set_tile(
            &mut vram,
            (x, y).into(),
            &tileset,
            TileSetting::new(0, false, false, 0),
        );
    }
}
bg.commit(&mut vram);
bg.show();