From d896adfad536248a838489c5681ffebc85a6a752 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 14 Feb 2022 22:23:02 +0000 Subject: [PATCH] Clear the backgrounds once they aren't used any more --- agb/src/display/background.rs | 4 ++++ examples/the-hat-chooses-the-wizard/src/main.rs | 8 +++++++- .../the-hat-chooses-the-wizard/src/splash_screen.rs | 11 ++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/agb/src/display/background.rs b/agb/src/display/background.rs index a21ab81..f786b9c 100644 --- a/agb/src/display/background.rs +++ b/agb/src/display/background.rs @@ -649,6 +649,10 @@ impl<'a> InfiniteScrolledMap<'a> { pub fn commit(&mut self) { self.map.commit(); } + + pub fn clear(&mut self, vram: &mut VRamManager) { + self.map.clear(vram); + } } fn div_floor(x: i32, y: i32) -> i32 { diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index 54ce0fc..535b5ee 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -660,6 +660,11 @@ impl<'a, 'b, 'c> PlayingLevel<'a, 'b> { self.background.background.hide(); } + fn clear_backgrounds(&mut self, vram: &mut VRamManager) { + self.background.background.clear(vram); + self.background.foreground.clear(vram); + } + fn dead_start(&mut self) { self.player.wizard.velocity = (0, -1).into(); self.player.wizard.sprite.set_priority(Priority::P0); @@ -812,7 +817,7 @@ fn main(mut agb: agb::Gba) -> ! { let mut music_box = sfx::MusicBox::new(); let vblank = agb::interrupt::VBlank::get(); - let mut current_level = 10; + let mut current_level = 11; loop { if current_level == map_tiles::LEVELS.len() as u32 { @@ -934,6 +939,7 @@ fn main(mut agb: agb::Gba) -> ! { } level.hide_backgrounds(); + level.clear_backgrounds(&mut vram); } splash_screen::show_splash_screen( diff --git a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs index 58b487c..61b7c68 100644 --- a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs +++ b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs @@ -19,16 +19,14 @@ pub fn show_splash_screen( vram: &mut VRamManager, ) { map.set_scroll_pos((0u16, 0u16).into()); - let tile_set_ref = match which { + let (tile_set_ref, palette) = match which { SplashScreen::Start => { let tile_set_ref = vram.add_tileset(TileSet::new( splash_screens::splash.tiles, TileFormat::FourBpp, )); - vram.set_background_palettes(splash_screens::splash.palettes); - - tile_set_ref + (tile_set_ref, splash_screens::splash.palettes) } SplashScreen::End => { let tile_set_ref = vram.add_tileset(TileSet::new( @@ -36,9 +34,7 @@ pub fn show_splash_screen( TileFormat::FourBpp, )); - vram.set_background_palettes(splash_screens::thanks_for_playing.palettes); - - tile_set_ref + (tile_set_ref, splash_screens::thanks_for_playing.palettes) } }; @@ -71,6 +67,7 @@ pub fn show_splash_screen( } map.commit(); + vram.set_background_palettes(palette); map.show(); loop {