From 983b56975c938e4225ff0fac0bc91750267b2493 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 14 Feb 2022 22:52:10 +0000 Subject: [PATCH] Try to fix splash screen crackle --- .../the-hat-chooses-the-wizard/src/main.rs | 43 ++++++++++--------- .../src/splash_screen.rs | 13 ++++++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index 563d9796..ad548088 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -657,7 +657,7 @@ impl<'a, 'b, 'c> PlayingLevel<'a, 'b> { fn hide_backgrounds(&mut self) { self.background.background.hide(); - self.background.background.hide(); + self.background.foreground.hide(); } fn clear_backgrounds(&mut self, vram: &mut VRamManager) { @@ -775,12 +775,27 @@ fn main(mut agb: agb::Gba) -> ! { let (tiled, mut vram) = agb.display.video.tiled0(); vram.set_background_palettes(tile_sheet::background.palettes); let mut splash_screen = tiled.background(Priority::P0); + let mut world_display = tiled.background(Priority::P0); let tile_set_ref = vram.add_tileset(TileSet::new( tile_sheet::background.tiles, TileFormat::FourBpp, )); + for y in 0..32u16 { + for x in 0..32u16 { + world_display.set_tile( + &mut vram, + (x, y).into(), + tile_set_ref, + TileSetting::from_raw(level_display::BLANK), + ); + } + } + + world_display.commit(); + world_display.show(); + splash_screen::show_splash_screen( splash_screen::SplashScreen::Start, None, @@ -790,6 +805,8 @@ fn main(mut agb: agb::Gba) -> ! { ); loop { + vram.set_background_palettes(tile_sheet::background.palettes); + let mut object = agb.display.object.get(); let mut timer_controller = agb.timers.timers(); let mut mixer = agb.mixer.mixer(&mut timer_controller.timer0); @@ -797,20 +814,6 @@ fn main(mut agb: agb::Gba) -> ! { object.set_sprite_palettes(object_sheet::object_sheet.palettes); object.set_sprite_tilemap(object_sheet::object_sheet.tiles); - for y in 0..32u16 { - for x in 0..32u16 { - splash_screen.set_tile( - &mut vram, - (x, y).into(), - tile_set_ref, - TileSetting::from_raw(level_display::BLANK), - ); - } - } - - splash_screen.commit(); - splash_screen.show(); - object.enable(); mixer.enable(); @@ -830,23 +833,21 @@ fn main(mut agb: agb::Gba) -> ! { mixer.after_vblank(); level_display::write_level( - &mut splash_screen, + &mut world_display, current_level / 8 + 1, current_level % 8 + 1, tile_set_ref, &mut vram, ); - splash_screen.commit(); - splash_screen.show(); + world_display.commit(); + world_display.show(); music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); mixer.after_vblank(); - vram.set_background_palettes(tile_sheet::background.palettes); - let mut background = InfiniteScrolledMap::new( tiled.background(Priority::P2), Box::new(move |pos: Vector2D| { @@ -909,7 +910,7 @@ fn main(mut agb: agb::Gba) -> ! { level.show_backgrounds(); - splash_screen.hide(); + world_display.hide(); loop { match level 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 61b7c681..cdf185ca 100644 --- a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs +++ b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs @@ -42,6 +42,19 @@ pub fn show_splash_screen( let mut input = agb::input::ButtonController::new(); + if let Some(ref mut mixer) = mixer { + if let Some(ref mut music_box) = music_box { + music_box.before_frame(mixer); + } + mixer.frame(); + } + + vblank.wait_for_vblank(); + + if let Some(ref mut mixer) = mixer { + mixer.after_vblank(); + } + for y in 0..20u16 { for x in 0..30u16 { map.set_tile(