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

Author Topic: Getting screen boundaries  (Read 4044 times)

0 Members and 1 Guest are viewing this topic.

nolanvance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Getting screen boundaries
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10826
    • View Profile
    • development blog
    • Email
Re: Getting screen boundaries
« Reply #1 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 quite interesting and might get some intuition on the topic.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nolanvance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Getting screen boundaries
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10826
    • View Profile
    • development blog
    • Email
Re: Getting screen boundaries
« Reply #3 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nolanvance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Getting screen boundaries
« Reply #4 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10826
    • View Profile
    • development blog
    • Email
AW: Getting screen boundaries
« Reply #5 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nolanvance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Getting screen boundaries
« Reply #6 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;

 

 

anything