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

Author Topic: [Solved] How to move a View  (Read 2712 times)

0 Members and 1 Guest are viewing this topic.

Cr0n

  • Newbie
  • *
  • Posts: 10
    • View Profile
[Solved] How to move a View
« on: June 13, 2020, 02:57:51 pm »
Sup!
I dont quite get my error here:

mWorldView.move(-100,400);
Does work perfectly fine - however:

When I first center some sprites relative to the view...

mPlayer.setPosition(mWorldView.getCenter());


They wont move if I move the View. I am confident that I only center them once.

Help appreciated
Cr0n :)
« Last Edit: June 14, 2020, 07:31:06 am by eXpl0it3r »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to move a View
« Reply #1 on: June 13, 2020, 03:34:44 pm »
Quote
They wont move if I move the View
Do you mean that they move on screen? Or that they stay at the same pixel position?
Laurent Gomila - SFML developer

Cr0n

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to move a View
« Reply #2 on: June 13, 2020, 04:03:39 pm »
no I really mean that they stay at the same pixel position

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to move a View
« Reply #3 on: June 13, 2020, 06:17:28 pm »
That's the expected behavior. The center of the view is always mapped to the center of the window (unless you play with the viewport, which I assume you don't). So if the player follows the center of the view, it always remains at the center of the window as well.

When you move the view, what should be moving is everything that doesn't move relatively to it (like a static background). If you want to see the player move, don't make him follow the view, that's simple.
Laurent Gomila - SFML developer

Cr0n

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to move a View
« Reply #4 on: June 13, 2020, 07:01:59 pm »
But as I said I dont let it follow the view??
I only set the player in the middle of the view once

Quote
mPlayer.setPosition(mWorldView.getCenter());


They wont move if I move the View. I am confident that I only center them once.

Cr0n

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to move a View
« Reply #5 on: June 13, 2020, 07:03:08 pm »
Ok now this is weird:

I have instanced another sf::View.
Thats my code structure with it:


sf::View view1;
sf::View view2;

while(window.isOpen(){
window.setView(view1);
...
...
window.clear();
window.draw(...);
window.display();
if(mode){
      window.setView(view2);
      ...

   }
}
elseif(otherMode){
   ...
   view1.move(x,y);
      window.clear();
      window.draw(....);
      window.display();
 

Makes the moving work!
But removing the window.setView(view2) part prevents it from working again.

Furthermore, I can set the bounds from view2 to whatever I like - the object from if(mode) are all at the same place - its like totally broken - im apparently not drawing to view2, but it still does something (that i didnt want but that somehow solved the other problem)

Cr0n

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to move a View
« Reply #6 on: June 13, 2020, 08:02:39 pm »
There's probably a mistake in your code logic. Please post a complete and minimal example that reproduces the problem, otherwise it will be hard to help you.
Laurent Gomila - SFML developer

Cr0n

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to move a View
« Reply #7 on: June 14, 2020, 12:52:10 am »
Uh ok it was a timing issue.
Case closed sorry for spam

 

anything