SFML community forums

Help => Graphics => Topic started by: MickeyKnox on June 19, 2020, 07:50:27 pm

Title: [SOLVED] How to move the View?
Post by: MickeyKnox on June 19, 2020, 07:50:27 pm
window.getView().move(0, 1);

doesn't work, because Window::getView is const, while View::move isn't.

How am I supposed to move the View?
Title: Re: How to move the View?
Post by: G. on June 19, 2020, 09:34:20 pm
Get your sf::View as a variable, move it, and set it with setView
Title: Re: How to move the View?
Post by: MickeyKnox on June 19, 2020, 11:02:18 pm
What do you mean by "Get your sf::View as a variable"?

The View from Window via getView()? Or do you mean a fresh View? How would I initialize that?

Everytime I move the View I have to set it with setView? Or can I move the view as much as I want once I've set it?


Edit:
I've tried setting a new View, but the Image is distorted.

I think that the default View in Window somehow gets initialized to my Desktop resolution (I'm running in fullscreen), but a new View gets some default resolution, resulting in a distorted Image. Initializing the View with the viewport from the view from window also didn't help.
Title: Re: How to move the View?
Post by: G. on June 20, 2020, 12:09:01 am
sf::View view = window.getView();
view.move(0, 1);
window.setView(view);

Yes, you have to set the view when you modify it.

You don't need to modify the viewport to just move the view.
View creation and how they work:
https://www.sfml-dev.org/tutorials/2.5/graphics-view.php
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1View.php
Title: Re: How to move the View?
Post by: MickeyKnox on June 20, 2020, 12:57:17 am
Thanks, especially for the link to the tutorial. That was very helpful.