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

Author Topic: getDesktopMode().width&height gets wrong tablet screen size  (Read 2142 times)

0 Members and 1 Guest are viewing this topic.

Saud

  • Newbie
  • *
  • Posts: 9
    • View Profile
getDesktopMode().width&height gets wrong tablet screen size
« on: November 23, 2018, 09:56:51 pm »
Hello,

I'm making a mini game for learning purposes, and recently i started testing the game on my Huawei android tablet with 1920, 1200 resolution.

when i use sf::VideoMode::getDesktopMode().height it returns 1133height and 1920width but the tablets height resolution is 1200.

The big issue is when i keep using 1133 as height of my sf::RenderWindow the sprites getGlobalBounds get messed up, its like when i touch point(200, 200) the tablet reads it as point(200, 266).

Is it possible to read exact screen resolution? or to change how the app read touch position?


note:
when putting the tablet to portrait mode, sf::VideoMode::getDesktopMode().height will be 1920-66 and width 1200.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: getDesktopMode().width&height gets wrong tablet screen size
« Reply #1 on: November 23, 2018, 11:19:34 pm »
Hey.
Do you pass your window as a second argument to sf::Touch::getPosition?

Saud

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: getDesktopMode().width&height gets wrong tablet screen size
« Reply #2 on: November 24, 2018, 02:23:31 pm »
Hey.
Do you pass your window as a second argument to sf::Touch::getPosition?


I make the renderwindow in main and then pass it to game levels functions as the only parameter,
then in the function, in while (window is open) loop, first thing there is to store sf::Touch::getPosition().x&y in local variables, then use these variables in sprite.getGlobalBounds().contains() .

edit:
and yep i use the renderwindow as a second argument in sf::Touch::getPosition
« Last Edit: November 24, 2018, 04:19:19 pm by Saud »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: getDesktopMode().width&height gets wrong tablet screen size
« Reply #3 on: November 25, 2018, 09:57:34 am »
Pixel coordinates and scene coordinates are two different things. Use RenderWindow::mapPixelToCoords and mapCoordsToPixel to convert from one to another.
Laurent Gomila - SFML developer

Saud

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: getDesktopMode().width&height gets wrong tablet screen size
« Reply #4 on: November 25, 2018, 01:27:21 pm »
Pixel coordinates and scene coordinates are two different things. Use RenderWindow::mapPixelToCoords and mapCoordsToPixel to convert from one to another.

Thank you,
I used
window.mapPixelToCoords(sf::Touch::getPosition(0, window))
and it worked, thnx again  :)

 

anything