So I'm working on a 2D game and right now I have a problem with drawing out my tiles. It laggs terribly and I don't really know what to do about it.
I got a set of tiles: Tile * tiles[32][32];
for(int i = 0; i < 32; i++)
{
for(int j = 0; j < 32; j++)
{
if(tile[j][i]->getPosition().x > (cameraCenter.x-cx-tss) &&
tile[j][i]->getPosition().x < (cameraCenter.x+cx+tss) &&
tile[j][i]->getPosition().y > (cameraCenter.y-cy-tss) &&
tile[j][i]->getPosition().y < (cameraCenter.y+cy+tss)){
renderWindow.draw(tile[j][i]->sprite);
}
}
}
This is my code when I draw it.
Now I tried drawing when my Tiles wasn't pointer and I had no lagg.
Is there a reason why this is ?
And is there someone who can give some pointers to one that is new in both c++ and SFML.
If you need more of anything, just ask.
Thanks
Don't use sprites for tile-maps but vertex arrays to get skyrocketing performances. ;)
I wonder why SFML doesn't provide something like XNA's SpritBatch. I wrote one for myself(.NET version), and for tilemaps it works just great.
As to the topic, how big are your tiles? 32x32 should fit on the screen.
Try this:
for(int x = 0; i < 32; y++)
{
for(int y = 0; y < 32; y++)
{
renderWindow.draw(tile[x][y]->sprite);
}
}