mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
add blending to the window example
This commit is contained in:
parent
ff5a1fbbba
commit
921c26f7c2
|
@ -1,9 +1,10 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
|
use agb::display::blend::{BlendMode, Layer};
|
||||||
use agb::display::{example_logo, tiled::RegularBackgroundSize, window::WinIn};
|
use agb::display::{example_logo, tiled::RegularBackgroundSize, window::WinIn};
|
||||||
use agb::display::{HEIGHT, WIDTH};
|
use agb::display::{HEIGHT, WIDTH};
|
||||||
use agb::fixnum::{Num, Rect, Vector2D};
|
use agb::fixnum::{num, Num, Rect, Vector2D};
|
||||||
use agb::interrupt::VBlank;
|
use agb::interrupt::VBlank;
|
||||||
|
|
||||||
type FNum = Num<i32, 8>;
|
type FNum = Num<i32, 8>;
|
||||||
|
@ -27,11 +28,27 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
.set_position(&Rect::new((10, 10).into(), (64, 64).into()))
|
.set_position(&Rect::new((10, 10).into(), (64, 64).into()))
|
||||||
.enable();
|
.enable();
|
||||||
|
|
||||||
|
window
|
||||||
|
.win_out()
|
||||||
|
.enable()
|
||||||
|
.set_background_enable(map.background(), true)
|
||||||
|
.set_blend_enable(true);
|
||||||
|
|
||||||
example_logo::display_logo(&mut map, &mut vram);
|
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<FNum> = (10, 10).into();
|
let mut pos: Vector2D<FNum> = (10, 10).into();
|
||||||
let mut velocity: Vector2D<FNum> = Vector2D::new(1.into(), 1.into());
|
let mut velocity: Vector2D<FNum> = Vector2D::new(1.into(), 1.into());
|
||||||
|
|
||||||
|
let mut blend_amount: Num<i32, 8> = num!(0.5);
|
||||||
|
let mut blend_velocity: Num<i32, 8> = Num::new(1) / 128;
|
||||||
|
|
||||||
let vblank = VBlank::get();
|
let vblank = VBlank::get();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -45,11 +62,21 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
velocity.y *= -1;
|
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
|
window
|
||||||
.win_in(WinIn::Win0)
|
.win_in(WinIn::Win0)
|
||||||
.set_position(&Rect::new(pos.floor(), (64, 64).into()));
|
.set_position(&Rect::new(pos.floor(), (64, 64).into()));
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
window.commit();
|
window.commit();
|
||||||
|
blend.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue