Sign in to follow this  
rhennig

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:

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!

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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: 

 

 

Share this post


Link to post
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.

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

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.