diff --git a/agb/examples/windows.rs b/agb/examples/windows.rs index ce4ee278..33d8a4f9 100644 --- a/agb/examples/windows.rs +++ b/agb/examples/windows.rs @@ -1,9 +1,10 @@ #![no_std] #![no_main] +use agb::display::blend::{BlendMode, Layer}; use agb::display::{example_logo, tiled::RegularBackgroundSize, window::WinIn}; use agb::display::{HEIGHT, WIDTH}; -use agb::fixnum::{Num, Rect, Vector2D}; +use agb::fixnum::{num, Num, Rect, Vector2D}; use agb::interrupt::VBlank; type FNum = Num; @@ -27,11 +28,27 @@ fn main(mut gba: agb::Gba) -> ! { .set_position(&Rect::new((10, 10).into(), (64, 64).into())) .enable(); + window + .win_out() + .enable() + .set_background_enable(map.background(), true) + .set_blend_enable(true); + example_logo::display_logo(&mut map, &mut vram); + let mut blend = gba.display.blend.get(); + + blend + .set_background_enable(Layer::Top, map.background(), true) + .set_backdrop_enable(Layer::Bottom, true) + .set_blend_mode(BlendMode::Normal); + let mut pos: Vector2D = (10, 10).into(); let mut velocity: Vector2D = Vector2D::new(1.into(), 1.into()); + let mut blend_amount: Num = num!(0.5); + let mut blend_velocity: Num = Num::new(1) / 128; + let vblank = VBlank::get(); loop { @@ -45,11 +62,21 @@ fn main(mut gba: agb::Gba) -> ! { velocity.y *= -1; } + blend_amount += blend_velocity; + if blend_amount > num!(0.75) || blend_amount < num!(0.25) { + blend_velocity *= -1; + } + + blend_amount = blend_amount.clamp(0.into(), 1.into()); + + blend.set_blend_weight(Layer::Top, blend_amount.try_change_base().unwrap()); + window .win_in(WinIn::Win0) .set_position(&Rect::new(pos.floor(), (64, 64).into())); vblank.wait_for_vblank(); window.commit(); + blend.commit(); } }