Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
4 Views

Orientation Lock landscape!

I created a menu for my game, so this menu can be displayed in landscape. I'm using the plugin Screen Orientation, in android works correctly.

How do I display this menu (made in Canvas + phaser js) is displayed only in landscape on the iPhone too ?!

* excuse the horrible English

Tags (2)
0 Kudos
3 Replies
Highlighted
4 Views

That plugin seems to work differently on iOS than it does on Android. Here's some sample code that might help you figure it out:

app.testToggleOrientation = function() {
    "use strict" ;
    var fName = "toggleOrientation():" ;
    app.consoleLog(fName, "entry") ;

    var str = "" ;
    var screenOrientation = "unknown" ;

    if( window.cordova ) {
        try {
            if( cordova.platformId.match(/ios/i) ) {
                screenOrientation = screen.orientation ;
            }
            else if( cordova.platformId.match(/android/i) ) {
                screenOrientation = screen.orientation.type ;
            }
            else {
                screenOrientation = "unknown" ;
            }

            if( screenOrientation.match(/landscape/i) ) {
                screenOrientation = "portrait" ;
                screen.lockOrientation(screenOrientation) ;
            }
            else if( screenOrientation.match(/portrait/i) ) {
                screenOrientation = "landscape" ;
                screen.lockOrientation(screenOrientation) ;
            }
            else {
                screenOrientation = "unlocked" ;
                screen.unlockOrientation() ;
            }

            str = "try succeeded, screen orientation set to: " + screenOrientation ;
            app.consoleLog(fName, str) ;
        }
        catch(e) {
            str = "try failed: " + e ;
            app.consoleLog(fName, str) ;
            app.alert(str) ;
        }
    }

//    app.flashBackground("#"+Math.floor(Math.random()*16777215).toString(16), 0) ;
    app.consoleLog(fName, "exit") ;
} ;



app.windowEventOrientationChange = function() {
    "use strict" ;
    var fName = "windowEventOrientationChange():" ;

    var str = "" ;
    var screenOrientation = "unknown" ;

    if( window.cordova ) {
        if( cordova.platformId.match(/ios/i) )
            screenOrientation = screen.orientation ;
        else if( cordova.platformId.match(/android/i) )
            screenOrientation = screen.orientation.type ;
    }

    str = "Screen orientation is: " + screenOrientation ;
    app.consoleLog(fName, str) ;
//    app.alert(str, 1000) ;
} ;
window.addEventListener("orientationchange", app.windowEventOrientationChange) ;

 

0 Kudos
Highlighted
Beginner
4 Views

how I implement?! can a help me?

0 Kudos
Highlighted
4 Views

Felipe -- the code I provided is quite clear on how to handle the differences between iOS and Android. Please read the code.

0 Kudos