Software Archive
Read-only legacy content
17061 Discussions

Orientation Lock landscape!

Felipe_X_
Beginner
234 Views

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

0 Kudos
3 Replies
PaulF_IntelCorp
Employee
234 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
Felipe_X_
Beginner
234 Views

how I implement?! can a help me?

0 Kudos
PaulF_IntelCorp
Employee
234 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
Reply