Jump to content

There is no enableOrientationCheck anymore. How How can I handle device orientation?


plicatibu
 Share

Recommended Posts

Hi, all.

 

I'm trying to handle the landscape / portrait mode in Phaser.

 

At first I thought to use the 

game.stage.enableOrientationCheck(false, true, 'please-rotate');

as show in this post  but there is a problem: I could not find the enableOrientationCheck method. It's not part of stage anymore.

 

I performed a grep into Phaser folder but the only reference to this function is in 

phaser/wip/TS Tests/mobile/sprite test 1.js

In short,it seems that this method was wiped out of Phaser's source code.

 

Is there any other reliable method I can force users to use device in either portrait or landscape mode or at least notify him to change device orientation?

 

I'm using Phaser 1.1.2.

 

Regards.

Link to comment
Share on other sites

To force portrait orientation, use the following:

game.stage.scale.forceOrientation(false, true, 'orientationImage');

Please note that forcing the portrait orientation doesn't work correctly, I reported the issue here.

 

To fix it, just add the following line at the beginning of StageScaleMode.forceOrientation():

this.forcePortrait = forcePortrait;
Link to comment
Share on other sites

@haden There is no function

forceOrientation

on Phaser 1.1.2.

 

@rich Shame on me. I should have looked more carefully on source code.

 

Any way I put the code

game.stage.scaleMode.forceLandscape = true;

in the create method of each and every state class but I saw no difference. The game continues to being re-sized in portrait mode.

 

Could you please tell me what am I missing?

   

Link to comment
Share on other sites

I updated the Phaser repository and then I switched to dev branch.

 

The device I used to test is Motorola Razor i XT890 (Android 4.1.2).

 

Then I used the following code in order to both force landscape and use full screen:

 


        this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;        this.game.stage.scale.minWidth = 480;        this.game.stage.scale.minHeight = 260;        this.game.stage.scale.maxWidth = 1024;        this.game.stage.scale.maxHeight = 768;        this.game.stage.scale.forceOrientation(true, false, 'r');        this.game.stage.scale.pageAlignHorizontally = true;        this.game.stage.scale.pageAlignVertically = true;        this.game.stage.scale.refresh();        this.game.stage.scale.maxIterations = 1;        if (this.game.device.android && this.game.device.chrome == false)        {            this.game.stage.scaleMode = Phaser.StageScaleMode.EXACT_FIT;        }        this.game.input.maxPointers = 1;        this.game.stage.disableVisibilityChange = true;        this.game.stage.scale.pageAlignHorizontally = true;        this.game.stage.scale.pageAlignVertically = true;

The point is that using device's stock browser the behavior from application was very strange when I stared changing it's position from portrait to landscape and vice-verse.

 

It doesn't happens when using Chrome browser in this Motorola device nor when using Safari on iPhone with iOS 6.1.3.

 

As my English is not enough to explain it, I made a video (just 1 minute) to show what is happening.

 

You can watch it here.

 

Any help is very much appreciated.

 

Edit: For a while the game can be played here in case anyone would like to test it and see the problem.

Link to comment
Share on other sites

Just to add: in the latest dev branch there are 2 new events you can listen to:

game.stage.scale.enterIncorrectOrientationgame.stage.scale.leaveIncorrectOrientation

So you can now listen to those to handle anything you need to do yourself. For example I had a requirement for a game where it should display a custom div over the top of the game when it the wrong orientation, so the above allowed me to do that. I could have done it with media queries too but I needed the game to pause while it was going on.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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