Replies: 1 comment 6 replies
-
Code for context: /// Display the game.
/// Returns how the game ended and the duration this scene took in number of frames (useful for seeding random numbers).
pub fn game_scene(ctx: Context) -> (GameResult, usize) {
let (video, mut vram) = ctx.gba.display.video.tiled0();
let mut frame: usize = 0;
let mut palettes = [
DEFAULT_BACKGROUND.palettes[0].clone(),
DEFAULT_BACKGROUND.palettes[0].clone(),
];
for c in 1..10 {
palettes[0].update_colour(c, GRASS_GREEN.to_u16());
}
let format = DEFAULT_BACKGROUND.tileset.tiles.format();
let mut bg = [
video.background(Priority::P3, RegularBackgroundSize::Background64x64, format),
video.background(Priority::P2, RegularBackgroundSize::Background64x64, format),
];
for y in 0..64 {
for x in 0..64 {
let position = Vector2D::new(x, y);
let index = (y * 64 + x) as usize;
for layer in 0..2 {
let tile = DEFAULT_BACKGROUND.layers[layer][index];
if tile > 0 {
bg[layer].set_tile(
&mut vram,
position,
&DEFAULT_BACKGROUND.tileset.tiles,
DEFAULT_BACKGROUND.tileset.tile_settings[(tile - 1) as usize],
);
}
}
}
}
ctx.vblank.wait_for_vblank();
frame = frame.wrapping_add(1);
vram.set_background_palettes(&palettes);
for layer in 0..2 {
bg[layer].set_scroll_pos(map_to_scroll(Vector2D::new(32 * 8, 32 * 8)));
bg[layer].set_visible(true);
bg[layer].commit(&mut vram);
}
// fade from menu green to actual palette
for n in 1..64 {
for c in 1..10 {
palettes[0].update_colour(c, Colour::interpolate(GRASS_GREEN, Colour::from(palettes[1].colour(c)), (n * 4 - 1) as u8).to_u16());
}
ctx.vblank.wait_for_vblank();
frame = frame.wrapping_add(1);
vram.set_background_palettes(&palettes);
}
(GameResult::GameOver { points: 0 }, frame)
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I am not sure, if this is a bug in agb or if I'm doing something wrong.
so right now I basically have a game scene, where I load my map at the beginning in tiled0. I'm using the background P3 and P2. both layers share the same tileset, but use different tiles of it.
so far this works. but when that scene finishes (right now that happens immediatly, but would usually happen when the player dies)
I loop back into the main menu.
my main menu has this special thing, that it doesn't do anything with background at all.
when first run, you still see the background that was previously set by the title screen.
and after looping back from the actual game, you still see the map in the background.
so far as expected.
now comes the funny thing: if I choose "new game" again, again the expected stuff happens. the game starts, does some stuff, and loops back to the main menu.
BUT: after doing that several times (choosing new game, watching it do its thing, and coming back to the main menu), at some point MGBA crashes with the message, that VRAM ran out of memory for tiles.
when I checked the tile window of mgba during a test run, I noticed, that it would add another full set of tiles to the vram on every run of the game scene function.
this kinda confuses me. I would expect one of two things to happen:
1.: because I reset the background at the start of the main game, I would expect the tiles to be cleared and reloaded
2.: because I actually keep using the same tiles, I would expect agbrs to just not load them again
in both cases the error I'm seeing would not happen. so I'm a bit confused, what's going on
Beta Was this translation helpful? Give feedback.
All reactions