1
Graphics / How to detect OnScreen Sprites when using views?
« on: July 10, 2012, 06:46:07 am »
I'm using a custom sf::View for my RenderWindow in my tile-based RPG. Now I use sf::View's Move() method to scroll around the map. Now the problem is, how do I detect the sprites that are currently on the screen? I tried this:
However, although it initially works fine, after I Move() the view, the sprite's positions aren't updated and new sprites that appear on the screen are not drawn. What should I do?
/** pro::Tile is derived from sf::Sprite **/
bool LevelRenderer::OnScreen(pro::Tile& tile, sf::RenderWindow& app)
{
return (tile.GetPosition().x > 0 && tile.GetPosition().x < app.GetWidth()
&& tile.GetPosition().y > 0 && tile.GetPosition().y < app.GetHeight());
}
bool LevelRenderer::OnScreen(pro::Tile& tile, sf::RenderWindow& app)
{
return (tile.GetPosition().x > 0 && tile.GetPosition().x < app.GetWidth()
&& tile.GetPosition().y > 0 && tile.GetPosition().y < app.GetHeight());
}
However, although it initially works fine, after I Move() the view, the sprite's positions aren't updated and new sprites that appear on the screen are not drawn. What should I do?