Jump to content

Problem with screen size in mobile device (Cordova)


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:


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). 


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".


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.


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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