Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] How to move the View?  (Read 2423 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
[SOLVED] How to move the View?
« 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?
« Last Edit: June 20, 2020, 12:57:42 am by MickeyKnox »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: How to move the View?
« Reply #1 on: June 19, 2020, 09:34:20 pm »
Get your sf::View as a variable, move it, and set it with setView

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: How to move the View?
« Reply #2 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.
« Last Edit: June 19, 2020, 11:15:16 pm by MickeyKnox »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: How to move the View?
« Reply #3 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

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: How to move the View?
« Reply #4 on: June 20, 2020, 12:57:17 am »
Thanks, especially for the link to the tutorial. That was very helpful.

 

anything