From 817e1e305e6eb76f830b57b8e1574fc029af2995 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Tue, 3 May 2022 23:00:31 +0100 Subject: [PATCH] Add rem_euclid_*_px for pixel calculations --- agb/src/display/tiled/infinite_scrolled_map.rs | 4 ++-- agb/src/display/tiled/mod.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/agb/src/display/tiled/infinite_scrolled_map.rs b/agb/src/display/tiled/infinite_scrolled_map.rs index 1af77c99..cef44351 100644 --- a/agb/src/display/tiled/infinite_scrolled_map.rs +++ b/agb/src/display/tiled/infinite_scrolled_map.rs @@ -190,8 +190,8 @@ impl<'a> InfiniteScrolledMap<'a> { let current_scroll = self.map.scroll_pos(); let new_scroll = ( - size.rem_euclid_width(current_scroll.x as i32 + difference.x) as u16, - size.rem_euclid_height(current_scroll.y as i32 + difference.y) as u16, + size.rem_euclid_width_px(current_scroll.x as i32 + difference.x) as u16, + size.rem_euclid_height_px(current_scroll.y as i32 + difference.y) as u16, ) .into(); diff --git a/agb/src/display/tiled/mod.rs b/agb/src/display/tiled/mod.rs index 2fabce54..12d8624c 100644 --- a/agb/src/display/tiled/mod.rs +++ b/agb/src/display/tiled/mod.rs @@ -55,6 +55,14 @@ impl RegularBackgroundSize { pub(crate) fn rem_euclid_height(&self, y: i32) -> u32 { (y as u32) & (self.height() - 1) } + + pub(crate) fn rem_euclid_width_px(&self, x: i32) -> u32 { + (x as u32) & (self.width() * 8 - 1) + } + + pub(crate) fn rem_euclid_height_px(&self, y: i32) -> u32 { + (y as u32) & (self.height() * 8 - 1) + } } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]