Make the example work the way I expect it to

This commit is contained in:
Gwilym Kuiper 2022-09-22 21:34:03 +01:00
parent 496b4a4953
commit 59673206b3
2 changed files with 15 additions and 13 deletions

View file

@ -6,7 +6,7 @@ use agb::{
tiled::{AffineBackgroundSize, TileFormat, TileSet, TiledMap},
Priority,
},
fixnum::num,
fixnum::{num, Num},
include_gfx,
input::Tri,
};
@ -33,7 +33,7 @@ fn main(mut gba: agb::Gba) -> ! {
bg.commit(&mut vram);
bg.show();
let mut rotation = num!(0.);
let mut rotation: Num<u16, 8> = num!(0.);
let rotation_increase = num!(1.);
let mut input = agb::input::ButtonController::new();
@ -56,10 +56,12 @@ fn main(mut gba: agb::Gba) -> ! {
_ => {}
}
bg.set_scroll_pos((16 * 4, 16 * 4).into());
let scroll_pos = (scroll_x as i16, scroll_y as i16);
bg.set_transform(
(-scroll_x as i16, -scroll_y as i16).into(),
(1, 1).into(),
rotation,
scroll_pos,
(1, 1),
rotation,
);
rotation += rotation_increase;

View file

@ -284,10 +284,10 @@ impl TiledMapPrivate for AffineMap {
&mut self.bg_center.y
}
fn x_scroll(&self) -> Self::Position {
self.bg_center.x
self.bg_center.x + self.transform.position.x
}
fn y_scroll(&self) -> Self::Position {
self.bg_center.y
self.bg_center.y + self.transform.position.y
}
fn affine_matrix(&self) -> Self::AffineMatrix {
self.transform.matrix
@ -375,15 +375,15 @@ impl AffineMap {
pub fn set_transform(
&mut self,
display_center: Vector2D<i16>,
scale: Vector2D<Num<i16, 8>>,
rotation: Num<u16, 8>,
display_center: impl Into<Vector2D<i16>>,
scale: impl Into<Vector2D<Num<i16, 8>>>,
rotation: impl Into<Num<u16, 8>>,
) {
self.set_transform_raw(crate::syscall::bg_affine_matrix(
self.bg_center,
display_center,
scale,
rotation,
display_center.into(),
scale.into(),
rotation.into(),
));
}
}