I ran into an issue with the way in which I'm doing it which is basically drawing a new image and text and resetting the screen
every time the player enter's or exits the options menu (changing a variable which tells the screen to change).
After returning from the menu for the 3rd or 4th time the game starts breaking ,in that it stops drawing to the screen
in the way it's supposed to. The code compiles fine without any issues or warnings.
main.c
Code: Select all
//...code...
titleScreen();
//Initialize joypad
JOY_init();
JOY_setEventHandler( &joyInput );
while(1)
{
//Wait for screen refresh
updateOptions();
optionState();
handleSprite(); //Is this the issue?
SPR_update();
VDP_waitVSync();
}
return 0;
Code: Select all
#include "commons.h"
#include "options.h"
//functions used in main c and or in the game loop
void titleScreen()
{
// Disable interrupts when accessing VDP
SYS_disableInts();
VDP_resetScreen();
// reset palettes
// Load images
VDP_drawImageEx(PLAN_A, &title_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 7, 2, FALSE, TRUE);
ind += title_image.tileset->numTile;
// Prepare palettes
memcpy(&palette[16], title_image.palette->data, 16 * 2);
VDP_setPalette(1, title_image.palette->data);
//VDP process done - re-enable interrupts
SYS_enableInts();
VDP_drawText("Start", 17, 22);
VDP_drawText("Options", 17, 24);
//timerCountdown();
}
void optionState()
{
if(options == 1)
{
SYS_disableInts();
VDP_resetScreen();
VDP_drawImageEx(PLAN_A, &blackscreen_image, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), 7, 4, FALSE, TRUE);
ind += blackscreen_image.tileset->numTile;
memcpy(&palette[32], blackscreen_image.palette->data, 16 * 2);
VDP_setPalette(2, blackscreen_image.palette->data);
SYS_enableInts();
options = 2;
//timerCountdown();
}
//...code for the other options...
}
Code: Select all
#include "sprite.h"
#include "variables.h"
Sprite *soaker[1];
void handleSprite()
{
u16 pal[64];
SYS_disableInts();
// Init sprites engine
SPR_init(8,128,128);
soaker[0] = SPR_addSprite(&soaker_sprite, posx-8, posy-3, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
// Prepare palettes
memcpy(&pal[32], soaker_sprite.palette->data, 16 * 2);
VDP_setPalette(2, soaker_sprite.palette->data);
SYS_enableInts();
}