I am again struggling. I am trying to create two views. The view is suppose to be menu and the other view the playing surface. Both views are covering the same space. I am currently trying to make views shift to different areas.
Here is my main rendering code;
_render.setView(_render.getDefaultView());
_render.setView(_menu.menuView(sf::FloatRect(0, 0, 0.5, 0.5)));
texture.draw(_menu.newBoard());
sf::View current = texture.getView();
_render.setView(_render.getDefaultView());
_play.viewport(sf::FloatRect(0, 0.5, 1, 1));
_render.setView(_play._view);
texture.draw(_play.draw());
sf::View currentview = texture.getView();
//Return drawing back to main window
_render.setView(_render.getDefaultView());
texture.display();
_render.clear();
And here is my viewport function:
_view.reset(sf::FloatRect(200, 200, 300, 200));
_view.setCenter(20, 20);
_view.setSize(800,800);
_view.setViewport(dimensions);
return _view;
Thanks.
One of those views you are making is going to cover the entire screen. They use a ratio of 0-1, so 1 is the entire width/height, depending on which parameter.
Here's what I usually do to create a view somewhere on the screen
sf::FloatRect SomeArea =
{
800, //Left
200, //Top
350, //Width
210 //Height
};
sf::View View;
sf::FloatRect Region =
{
SomeArea.left / WindowSize.x, //The ratio of how far from the right I want my view to start compared to how wide the screen is
SomeArea.top / WindowSize.y,//The ratio of how far from the top I want my view to start
SomeArea.Width / WindowSize.x, //The ratio of how wide I want the view to be to how wide the screen is
SomeArea.height / WindowSize.y //The ratio of how tall I want the view to be to how tall the screen is
};
View.setViewport(Region);
/*Use view however you wanted*/
I use views for clipping usually, but also for minimaps, etc.