use new api for backgrounds

This commit is contained in:
Corwin Kuiper 2021-04-28 03:10:10 +01:00
parent 12e01d6e01
commit f240f60013

View file

@ -3,7 +3,7 @@
extern crate agb;
use agb::display::{example_logo, tiled0};
use agb::display::example_logo;
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
@ -11,31 +11,19 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
let mut gfx = gba.display.video.tiled0();
gfx.set_background_palettes(example_logo::PALETTE_DATA);
gfx.set_background_tilemap(example_logo::TILE_DATA);
gfx.set_background_tilemap(0, example_logo::TILE_DATA);
gfx.background_0.enable();
gfx.background_0
.set_background_size(tiled0::BackgroundSize::S32x32);
gfx.background_0
.set_colour_mode(tiled0::ColourMode::FourBitPerPixel);
let mut back = gfx.get_background().unwrap();
gfx.background_0.set_screen_base_block(20);
let mut entries: [u16; 32 * 20] = [0; 32 * 20];
for i in 0..(32 * 20) {
let x = i % 32;
let y = i / 32;
if x >= 30 {
continue;
}
let tile_id = (x + y * 30) as u16;
let mut entries: [u16; 30 * 20] = [0; 30 * 20];
for tile_id in 0..(30 * 20) {
let palette_entry = example_logo::PALETTE_ASSIGNMENT[tile_id as usize] as u16;
entries[i] = tile_id | (palette_entry << 12);
entries[tile_id as usize] = tile_id | (palette_entry << 12);
}
gfx.copy_to_map(20, &entries);
back.set_map(&entries, 30, 20);
back.set_position(0, 0);
back.show();
loop {}
}