I am working on a RTS game and game gets laggy with big maps so I need to limit which parts of map to draw.
I want to draw only visible part of map so I coded like that:
void Node::draw( sf::RenderWindow& window )
{
sf::Vector2f node_position_in_coords;
sf::View view = window.getView();
sf::Rect<float> rt;
rt.left = view.getCenter().x - view.getSize().x/2.f;
rt.top = view.getCenter().y - view.getSize().y/2.f;
rt.width = view.getSize().x;
rt.height = view.getSize().y;
node_position_in_coords = window.mapPixelToCoords( sf::Vector2i( _x, _y) );
if( rt.contains( node_position_in_coords ) )
window.draw( _s_tile );
}
But it only draws a specific part of map.