I'm currently developing my own game. Every stage is already done and I can start game from beginning and finish it (I call this "first game loop").
But then when I start again to play ( "2nd game loop"), sooner or later, I found a black screen, with no sprites loaded in VRAM (but background tiles are loaded). CPU is working, I check 68k and it's working in a sort of loop. Then game is active, but nothing happens.
I tried to modify code. When I "fix/change" something in one stage, black screen appears in another stage.
I'm not using dynamic memory. Just in the begining I load my own config.h file with some global variables and some global structs, after that every stage.c has its local variables and they are destroyed after leaving function.
Also I track every sprite created and release before finishing stage. Also using VPP_init() after finishing every stage.
I though about tileSets, but I'm releasing ( Mem_free()/free() functions ) before leaving every stage using tilesets so.... I'm lost
Would you be so kind to help me?
- At this moment only solution is making a hard reset when finishing game... but I want to know what is wrong and where is the problem.
Take note still don't using music/sfx, not using Z80 at all.
Take note using old sgdk release, I modify code to use lastest sgdk, problem still there, so I return to old sgdk as it0s not sgdk related.
This is my skeleton stage function:
Code: Select all
void stageXX(){
SYS_disableInts();
VDP_setScreenWidth320();
SPR_init();
Game.time = 0;
Game.level = XX;
VDP_setPaletteColors(0, (u16*) palette_black, 64);
memcpy(&Game.palette[ 0], stage1.palette->data, 16 * 2);
memcpy(&Game.palette[16], sprite_player.palette->data, 16 * 2);
memcpy(&Game.palette[32], sprite_xxxxx.palette->data, 16 * 2);
memcpy(&Game.palette[48], sprite_yyyyyy.palette->data, 16 * 2);
VDP_drawImageEx(PLAN_B, &stage1, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, Game.index_planB), 0, 0, FALSE, TRUE);
Game.index_planA = Game.index_planB + stage1.tileset->numTile;
..similar to PLAN_A...
create_IU();
create_player();
....all create_functions() here...
VDP_fadeIn(0, (4 * 16) - 1, Game.palette, 60, FALSE);
VDP_waitFadeCompletion();
SYS_enableInts();
//main stage loop
while (1) {
control_IU();
control_read_pad();
control_player();
...all control_functions()... here
Game.time++;
if(Game.points>LIMIT) break; //to NEXT stage
SPR_update();
VDP_waitVSync();
}
//borra todo antes de terminar la fase
delete_player();
...all delete_functions();... here //release sprites
//free memory tilesets (only if necessary)
MEM_free(Game.tileset01);
Game.Estructura1 = NULL;
VDP_setHilightShadow(0); //Disable HL/S mode (only if necessary)
//reset VDP indexs
Game.index_planA = 1;
Game.index_planB = 1;
Game.index_planTop = 1;
VDP_init();
}