Hello all,
I am having a little trouble with my side scrolling tile map, at the moment. At the moment I scroll (when I need to) by moving the map left or right (seen as tileofsetX/Y later on) when I need to. There are various culling methods to make sure I only move the ones that can be seen (mapofsetX/Y again, for later on).
so here is my trouble, at the moment all of tiles are pointers, fair enough right?, However, there was a slight problem with this, I would have to initialise each tile separately (Load the texture, set the sprite, etc). As the map the map can have a lot of tiles on it, initialising each tile takes a big toll on the computer - takes 10+ seconds to open a 50x50 map.
I managed a work around by referencing a pre-existing tile:
void Room::init(Graphics *g){
roomSizeX=30;
roomSizeY=30;
normtile.init(g);
othertile.init(g);
for (UINT i = 0; i < roomSizeY; i++)
{
for (UINT j = 0; j < roomSizeX; j++)
{
if(i==0||i==roomSizeX-1||j==roomSizeY-1||j==0 || j%5==0)
roomMap[j][i] = &othertile;
else
roomMap[j][i] = &normtile;
roomMap[j][i]->setXLocation(j*64);
roomMap[j][i]->setYLocation(i*64);
}
}
}
However I do need to constantly set the position of each tile. Which works however, I'm not sure how, surely I would get some flickering?
ingame class:
void GuiIngame::draw(){
// Start draw end draw Check if drawing map
for (int i =camera.top; i <camera.bottom && i < levelMap[0][0]->getRoomSizeY(); i++)
{
for (int j = camera.left; j <camera.right && j < levelMap[0][0]->getRoomSizeX(); j++)
{
levelMap[0][0]->getTile(j,i)->setXLocation((int) ((j*(TILE_SIZE * scale))-(mapOfsetX*(TILE_SIZE * scale))-tileOfsetX) );
levelMap[0][0]->getTile(j,i)->setYLocation((int)((i*((TILE_SIZE) * scale))-(mapOfsetY*((TILE_SIZE) * scale))-tileOfsetY));
levelMap[0][0]->getTile(j,i)->getTileImage().draw();
}
}
}
However, I can not 'effectively' test for collisions with this basis, as the levelMap[0][0]->getTile(0,0)->getX/Y() Returns the last Tile's value for every tile.
If I made the tiles 'regular old objects' I would not be able to scroll the map, as it would just move the 'copied object - tile'.
Any help/advice would be appreciated.
Thanks