Jump to content

Problem with screen size in mobile device (Cordova)


rhennig
 Share

Recommended Posts

Hello! I'm having some troubles positioning objects on the screen of my mobile device using Cordova... I'm getting the screen height with:

totalHeight=this.sys.game.config.height/window.devicePixelRatio;

But when I try to put my object on the bottom of the screen with:

ground.create(totalwidth/2, totalHeight, 'ground');

It works perfectly on the browser but on the mobile device it is not totally on the bottom (maybe someting like 80%~90% from the bottom), and I'm not getting why (I've tryed to change the setOrigin value but doesnt fixed the problem)...

Is there something that I'm missing? 

Thanks in advance!

Link to comment
Share on other sites

I'd suggest checking your console for the Cordova build to see what the specs are for the actual Phaser canvas element. Are you using any plugins for the statusbar?

Also, with the recent fix to the game resolution, you can set the pixel ratio in the game config (resolution: window.devicePixelRatio) and not worry about it after that, and just use this.sys.game.config.height/width.

Link to comment
Share on other sites

Hi, no, I'm not using any plugins.

It's just a simple test. To clarify, this is how the code runs with cordova on the browser (cordova run browser). 

browser.jpg.988bd4083c3cf0b4ffccd78ad8d0a061.jpg

Using this code to set the ground position:

ground.create(totalwidth/2, totalheight, 'ground').setOrigin(0.5, 1);

And this is the same code on the device. As you can see there is a blank space below the "ground".

mobile.png.186a573b48f45e19ffd980e99942fb79.png

Link to comment
Share on other sites

Hmm that's weird I've just recently ported several of my Phaser games to Android with the help of Cordova and I didn't run into this issue.

totalHeight=this.sys.game.config.height/window.devicePixelRatio;

I think this is why the position is different because you take the devicePixelRatio into account for your in-game positions. However your game world should be independent of the device's screen size. If you simply use config.height it should work.

You want to take the devicePixelRatio into account for your game scaling. I'm answering you because by coincidence I've just posted an answer here where I explain how I scale my games for mobile - and it is working perfectly for me with Cordova, as well: 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...