Code: Select all
// Start with level one. Here is an example of how I'm loading the map.
void LevelOne()
{
u16 ind = TILE_USERINDEX;
Map *map = unpackMap(levelOne_planA.map, NULL);
Map *mapBG = unpackMap(levelOne_planB.map, NULL);
VDP_loadTileSet(levelOne_planB.tileset, ind, NULL);
VDP_setMapEx(BPLAN, mapBG, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, 0, 0, 32, 32);
ind += levelOne_planB.tileset->numTile;
VDP_loadTileSet(levelOne_planA.tileset, ind, NULL);
VDP_setMapEx(APLAN, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, 0, 0, 32, 32);
ind += levelOne_planA.tileset->numTile;
while(level == 1)
{
// Logic for updating the level
}
MEM_free(map);
MEM_free(mapBG);
}
//When I transition to level two, I follow similar logic to loading the map.
void LevelTwo()
{
u16 ind = TILE_USERINDEX;
Map *map = unpackMap(levelTwo_planA.map, NULL);
Map *mapBG = unpackMap(levelTwo_planB.map, NULL);
VDP_loadTileSet(levelTwo_planB.tileset, ind, NULL);
VDP_setMapEx(BPLAN, mapBG, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, 0, 0, 32, 32);
ind += levelTwo_planB.tileset->numTile;
VDP_loadTileSet(levelTwo_planA.tileset, ind, NULL);
VDP_setMapEx(APLAN, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, 0, 0, 32, 32);
ind += levelTwo_planA.tileset->numTile;
while(level == 2)
{
// Logic for updating the level
}
MEM_free(map);
MEM_free(mapBG);
}
I am able to resolve the issue by loading all tilemaps upfront, and keep a reference to where the ind starts for each level. Please see an example of this logic below:
Code: Select all
u16 levelOne_planAInd;
u16 levelOne_planBInd;
u16 levelTwo_planAInd;
u16 levelTwo_planBInd;
void main()
{
u16 ind = TILE_USERINDEX;
levelOne_planBInd = ind;
VDP_loadTileSet(levelOne_planB.tileset, ind, NULL);
ind += levelOne_planB.tileset->numTile;
levelOne_planAInd = ind;
VDP_loadTileSet(levelOne_planA.tileset, ind, NULL);
ind += levelOne_planA.tileset->numTile;
levelTwo_planBInd = ind;
VDP_loadTileSet(levelTwo_planB.tileset, ind, NULL);
ind += levelTwo_planB.tileset->numTile;
levelTwo_planAInd = ind;
VDP_loadTileSet(levelTwo_planA.tileset, ind, NULL);
ind += levelTwo_planA.tileset->numTile;
while(1)
{
while(level == 1) { LevelOne(); }
while(level == 2) { LevelTwo(); }
}
}
void LevelOne()
{
Map *map = unpackMap(levelOne_planA.map, NULL);
Map *mapBG = unpackMap(levelOne_planB.map, NULL);
// Change level to load based on ind set in main
VDP_setMapEx(BPLAN, mapBG, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, levelOne_planBInd), 0, 0, 0, 0, 32, 32);
VDP_setMapEx(APLAN, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, levelOne_planAInd), 0, 0, 0, 0, 32, 32);
while(level == 1)
{
// Logic for updating the level
}
MEM_free(map);
MEM_free(mapBG);
}
...