SFML community forums

Help => Window => Topic started by: nolanvance on February 20, 2013, 09:28:13 pm

Title: Getting screen boundaries
Post by: nolanvance on February 20, 2013, 09:28:13 pm
I've searched the forums for a couple of days but came up short..

Basically I'm just trying to get the screen boundaries so I can make my character stay in the window.

I'm having issues with the coordinate system. My scene coordinates are way off. (0,0) is towards the bottom left of the screen but the views coordinates are set at width/2 and height/2. This is throwing my calculations way off.

I guess my question is why are my scene coordinates wrong?
Title: Re: Getting screen boundaries
Post by: eXpl0it3r on February 20, 2013, 09:34:37 pm
Well we can't tell you what you're doing wrong, since we have no idea what you're doing, that means you'll have to show code, at best a complete and minimal example that reproduces the problems.

Additionally you'll probably find my tutorial on sf::View (https://github.com/SFML/SFML/wiki/Tutorial%3A-Using-View) quite interesting and might get some intuition on the topic.
Title: Re: Getting screen boundaries
Post by: nolanvance on February 20, 2013, 10:12:46 pm
sf::Vector2f top;
top = sf::Vector2f(0,tools->ReturnView().getSize().y*.65);

if(players[0].ReturnSprite().getPosition().y <= top.y)
        players[0].StopMovement(true);
 

Let me revise, I want to convert players coordinates to the screen coordinates (like mouse::getPosition())

For example my screen is 1200, and I want to not 65% of the screen to be off limits to the player.

top.y is = 540 which is right , but the players coordinates at the same place is equal to  abou -290
Title: Re: Getting screen boundaries
Post by: eXpl0it3r on February 20, 2013, 10:19:48 pm
So you're essentially searching for window.mapPixelToCoords or if you're still using SFML 2rc window.convertCoords, right?
Title: Re: Getting screen boundaries
Post by: nolanvance on February 21, 2013, 01:20:57 am
yeah man I tried that but it just spits out the same number.  :(

I am also using 2.0 rc
Title: AW: Getting screen boundaries
Post by: eXpl0it3r on February 21, 2013, 07:57:53 am
Have you read my tutorial I linked above, because I think you're usin views wrong.

If you want good help responses, you'll need to provide a complete and minimal example we can work with. ;)
Title: Re: Getting screen boundaries
Post by: nolanvance on February 22, 2013, 09:19:49 pm
I've been using this function to keep aspect ratio when changing resolution.

 
        window.create(sf::VideoMode(resX,resY),"asdasda",sf::Style::Fullscreen);
       
        int newH = (width*resY)/resX;
        int displace = (newH - height)/(-2);

        v1 = sf::View(sf::FloatRect(0,displace,width,newH));
        v1.setCenter(width/2,height/2);

        window.setView(v1);
       
        height = resY;
        width = resX;