Hello. I've been creating a tile engine based off of Nick Gravelyn's "old" tile engine tutorials(which are made with C#/XNA). I'm doing mine in C++/SFML but I seem to be having some issues drawing the tiles. The code below is the function that I'm currently using to draw the tiles. I'm encountering a few problems:
1. First of all, it takes at least four seconds to draw these 70 tiles
2.When it's done drawing, I end up with a checkerboard of empty spaces and tiles(alternating)
3.While drawing, all the tiles blink, even where there should be a tile in a blank spot.
Hopefully these can all be fixed in one fell swoop
void drawTiles(sf::RenderWindow &app)
{
for(int x = 0; x < tileMapWidth; x++)
{
for (int y = 0; y < tileMapHeight; y++)
{
int* textureIndex = tileMap[y, x];
sf::Texture texture = tileTextures[0]; //[*textureIndex+1];
sf::Sprite sprite;
sprite.Scale(.1875, .1875); // 48/256 (tileWidth/size of original image)
sprite.SetTexture(texture);
sprite.SetPosition(x*tileWidth,y*tileHeight);
app.Draw(sprite);
app.Display();
}
}
}
If you have any questions/comments on the code, feel free to ask. I can post the whole thing if needed, but I'll see if anyone can tell what's wrong by just seeing this function.