Loading Tilesets for different levels
Posted: Wed Apr 29, 2015 12:29 am
Hi, I'm having trouble understanding how to load tilesets properly for multiple images to use with different levels. I want to load two images to use for the APLAN and BPLAN for one level. Then change to another level using different images for the APLAN and BPLAN. When I load the tilesets in the code for each level, I run into an issue where the second level doesn't load properly. See below for an example of this:
When I use the logic above to load both levels, levelTwo does not load correctly. It looks like VDP_setMapEx() is not using the right tiles to load the level. I'm thinking that I'm not setting 'ind' correctly, but I don't understand why.
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:
I'm not sure if I'm loading tilesets correctly. Will I need to keep a reference of where the tile index is for each tileset? It seems like I'm missing something on how to set the tile index correctly, without having to keep a reference of where the index starts for each tileset.
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);
}
...