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

Author Topic: sf::View strange behaviour  (Read 1830 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
sf::View strange behaviour
« on: July 24, 2013, 09:38:35 am »
My windows is 1300x690. When the view is default my "map" renders properly:
http://postimg.org/image/lryrfrhlh/full/

Now I want using view place my map at position (400, 0) with size (900 x 690).
So I use:
sf::View view = window.getView();
view.setViewport(sf::FloatRect(400.f/1300.f, 0, 900.f/1300.f, 1));
view.setSize(900, 690);
window.setView(view);
 

Now the map rendering position is moved by a few tiles (look there are no green tiles on the left):
http://postimg.org/image/s6xscfob9/

Is it something wrong here or it is how view works? If so, how can I use viewport without changing the rendering position of things?

After applying viewport at (400, 0), I want (0, 0) position when rendering be at (400, 0)... It seems quite logic to me. But it is at about (335, 0) or so, I don't understand it really.
« Last Edit: July 24, 2013, 09:44:27 am by netrick »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::View strange behaviour
« Reply #1 on: July 24, 2013, 10:20:23 am »
You have to adjust your center of the view because you make it smaller. Otherwise the left top corner wont be at (0|0)

sf::View view = window.getDefaultView();
view.setViewport(sf::FloatRect(400.f/1300.f, 0, 900.f/1300.f, 1));
view.setSize(900, 690);
view.setCenter(450, 345);
window.setView(view);
 


AlexAUT

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: sf::View strange behaviour
« Reply #2 on: July 24, 2013, 10:46:00 am »
Thank you, it's working now.

 

anything