[v0.21.3] InfiniteScrollMap offset issue #895
-
|
Hey, I need a little help figuring out this strange issue related to InfiniteScrollMap. I've been using The Purple Night as an reference but not I'm stuck here and I don't know what is causing it. What I expected was flawless scroll of map at the same y coordinate while incrementing x position and setting it to this map. I'm using v0.21.3 version of agb. main.rs extern crate alloc;
mod level;
use agb::{
display::{
tiled::{
InfiniteScrolledMap, RegularBackgroundSize
}, Priority
},
include_background_gfx,
input::{Button, ButtonController},
fixnum::Vector2D,
sound::mixer::Frequency
};
use alloc::boxed::Box;
include_background_gfx!(basic_tiles,
basic => deduplicate "gfx/tiles.png",
);
#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
use agb::display::tiled::PartialUpdateStatus;
let vblank = agb::interrupt::VBlank::get();
let (gfx, mut vram) = gba.display.video.tiled0();
let mut mixer = gba.mixer.mixer(Frequency::Hz18157);
mixer.enable();
let mut button_controller = ButtonController::new();
let tileset = &basic_tiles::basic.tiles;
vram.set_background_palettes(basic_tiles::PALETTES);
let mut bg = InfiniteScrolledMap::new(
gfx.background(
Priority::P3,
RegularBackgroundSize::Background32x32,
tileset.format(),
),
Box::new(|pos| {(
&basic_tiles::basic.tiles,
basic_tiles::basic.tile_settings[
*level::ARRAY.get(
(pos.x + level::WIDTH * pos.y) as usize
).unwrap_or(&0)
],
)
}),
);
let mut between_updates = || {
mixer.frame();
vblank.wait_for_vblank();
};
let mut camera_position = Vector2D::new(0, 0);
bg.init(&mut vram, camera_position, &mut between_updates);
bg.commit(&mut vram);
bg.set_visible(true);
loop {
button_controller.update();
if button_controller.is_just_pressed(Button::RIGHT) {
camera_position.x += 8
}
if button_controller.is_just_pressed(Button::LEFT) {
camera_position.x -= 8
}
if button_controller.is_just_pressed(Button::UP) {
camera_position.y -= 8
}
if button_controller.is_just_pressed(Button::DOWN) {
camera_position.y += 8
}
while let PartialUpdateStatus::Continue = bg.set_pos(&mut vram, camera_position) {
mixer.frame();
vblank.wait_for_vblank();
}
bg.commit(&mut vram);
}
}level.rs pub const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3, 2, 3, 4, 5, 0, 0,
10,11, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9,10,11,10,11,10,11, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9,10,11, 0, 0,
4, 5, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 4, 5, 0, 0,
10,11, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9,10,11, 0, 0,
4, 5, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 4, 5, 0, 0,
10,11, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9,10,11, 0, 0,
4, 5, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 4, 5, 0, 0,
10,11, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9,10,11, 0, 0,
4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 0, 0,
10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11,10,11, 0, 0,
]; |
Beta Was this translation helpful? Give feedback.
Answered by
corwinkuiper
Apr 7, 2025
Replies: 1 comment 1 reply
-
Hope that helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Kiel97
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



rem_euclidfor this purpose. Modulo is quite expensive on thumb even if the value is known at compile time, that is unless the value is a power of 2.Hope that helps!