SFML community forums

Help => Graphics => Topic started by: netrick on July 24, 2013, 09:38:35 am

Title: sf::View strange behaviour
Post by: netrick 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/ (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/ (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.
Title: Re: sf::View strange behaviour
Post by: AlexAUT 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
Title: Re: sf::View strange behaviour
Post by: netrick on July 24, 2013, 10:46:00 am
Thank you, it's working now.