Hi there, im having some trouble streaming sprites that are within screen space. For example if i have 5000 sprites in my level but only 500 are within the screen, i only want to draw those 500 and not blindly draw the full 5000.
Here's some code, note that the windows view is always centered on
pEngine->get_player().
for (auto& ColumnTile : Row)
{
//Trying to check if tile is within the screen? or am i wrong
if (ColumnTile.graphics_shape().getPosition().x > pEngine->get_player()->getPosition().x - (RenderTarget.getSize().x / 2) &&
ColumnTile.graphics_shape().getPosition().x < pEngine->get_player()->getPosition().x + (RenderTarget.getSize().x / 2) &&
ColumnTile.graphics_shape().getPosition().y > pEngine->get_player()->getPosition().y - (RenderTarget.getSize().y / 2) &&
ColumnTile.graphics_shape().getPosition().y < pEngine->get_player()->getPosition().y + (RenderTarget.getSize().y / 2)
)
{
//draw if it's on the screen
RenderTarget.draw(ColumnTile);
}
}
The problem is half of the map dissapears (is not drawn), or to many sprites are drawn when they shouldn't be - it just doesn't work. Anyone have any idea why?
Help is much appreciated, thanks.
EDIT: Also the sprites are definatly initialized to the correct position, as they are all drawn perfect without the attempted bounds check.