But it renders the tiles from the center and down to the right ( It only draws tiles on 1/4 of the actual window ). How do I get it to align correctly and draw the entire screen full of the tiles.
Read the documentation of sf::FloatRect
You just copied and pasted the view's center and size in it, without checking what arguments it expects.
Your second code looks good, but the formula is probably wrong (the view's size doesn't appear in it).
I'll do it when I get home later today! Thanks for the quick replys Laurent.
The Indexed Culling actually worked like a charm!
Here is the code I did last night ( I get around 750 FPS on a 10000 by 10000 map ):
/* Culling code */
int startX = (veiw.getCenter().x - ( 20 * TILE_WIDTH))/TILE_WIDTH;
int endX = (veiw.getCenter().x + ( 20 * TILE_WIDTH))/TILE_WIDTH;
int startY = (veiw.getCenter().y - ( 20 * TILE_HEIGTH))/TILE_HEIGTH;
int endY = (veiw.getCenter().y + ( 20 * TILE_HEIGTH))/TILE_HEIGTH;
if(startX > MAP_WIDTH)
startX = MAP_WIDTH;
if(startX < 0)
startX = 0;
if(startY > MAP_HEIGTH)
startY = MAP_HEIGTH;
if(startY < 0)
startY = 0;
if(endY > MAP_HEIGTH)
endY = MAP_HEIGTH;
if(endY < 0)
endY = 0;
if(endX > MAP_WIDTH)
endX = MAP_WIDTH;
if(endX < 0)
endX = 0;
for(int y = startY; y < endY; y++)
{
for(int x = startX; x < endX; x++)
{
sprite.setPosition(x * TILE_WIDTH, y * TILE_HEIGTH);
window.draw(sprite);
}
}
EDIT:
I think I realized what you ment by not using my view's size. It's that the code doesn't dynamically adjust itself to another resolution so if I were to support a larger resolution their is a risk that the tiles I'm drawing wont cover the screen area. Is that what you meant?
EDIT 2:
I think I managed to actually get the culling using the view right this time:
It's drawing the entire screen full of tiles and the maximum tiles it's drawing is about 520 per frame which is sounds about right.
Here is the code I'm currently using
sf::FloatRect screenRect(sf::Vector2f(veiw.getCenter().x - (veiw.getSize().x)/2, veiw.getCenter().y - (veiw.getSize().y)/2) , veiw.getSize());
std::cout << "View X = " << veiw.getCenter().x - veiw.getSize().x << " " << "View Y = " << veiw.getCenter().y - veiw.getSize().y << std::endl;
window.clear(sf::Color::Black);
int tilesDrawn = 0;
for(int y = 0; y < MAP_HEIGTH; y++)
{
for(int x = 0; x < MAP_WIDTH; x++)
{
sprite.setPosition(x * TILE_WIDTH, y * TILE_HEIGTH);
sf::FloatRect collider(sprite.getGlobalBounds().left, sprite.getGlobalBounds().top, TILE_WIDTH, TILE_HEIGTH);
if(screenRect.intersects(collider))
{
window.draw(sprite);
tilesDrawn++;
}
}
}
std::cout << "Tiles Drawn: " << tilesDrawn << std::endl;
I'm eagerly waiting for your reply Laurent
I really hope I got it right this time.