pub struct Windows<'gba> { /* private fields */ }
Expand description
The windows feature of the Game Boy Advance can selectively display backgrounds or objects on the screen and can selectively enable and disable effects. This gives out references and holds changes before they can be committed.
Implementations§
source§impl<'gba> Windows<'gba>
impl<'gba> Windows<'gba>
sourcepub fn win_out(&mut self) -> &mut Window
pub fn win_out(&mut self) -> &mut Window
Returns a reference to the window that is used when outside all other windows
Examples found in repository?
examples/windows.rs (line 34)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let mut map = gfx.background(
agb::display::Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);
let mut window = gba.display.window.get();
window
.win_in(WinIn::Win0)
.set_background_enable(map.background(), true)
.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<FNum> = (10, 10).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();
loop {
pos += velocity;
if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
velocity.x *= -1;
}
if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
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();
}
}
sourcepub fn win_in(&mut self, id: WinIn) -> &mut MovableWindow
pub fn win_in(&mut self, id: WinIn) -> &mut MovableWindow
Gives a reference to the specified window that has effect when inside of it’s boundary
Examples found in repository?
examples/windows.rs (line 28)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let mut map = gfx.background(
agb::display::Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);
let mut window = gba.display.window.get();
window
.win_in(WinIn::Win0)
.set_background_enable(map.background(), true)
.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<FNum> = (10, 10).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();
loop {
pos += velocity;
if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
velocity.x *= -1;
}
if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
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();
}
}
sourcepub fn win_obj(&mut self) -> &mut Window
pub fn win_obj(&mut self) -> &mut Window
Gives a reference to the window that is controlled by sprites and objects
sourcepub fn commit(&self)
pub fn commit(&self)
Commits the state of the windows as dictated by the various functions to modify them. This should be done during vblank shortly after the wait for next vblank call.
Examples found in repository?
examples/windows.rs (line 81)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let mut map = gfx.background(
agb::display::Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);
let mut window = gba.display.window.get();
window
.win_in(WinIn::Win0)
.set_background_enable(map.background(), true)
.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<FNum> = (10, 10).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();
loop {
pos += velocity;
if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
velocity.x *= -1;
}
if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
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();
}
}