[Monkey] [Android] getOrientation()
Übersicht

![]() |
FarbfinsternisBetreff: [Android] getOrientation() |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da ich weder in den Modulen noch im englischen Forum etwas dazu gefunden habe, habe ich mir den Krimskram selbst implementiert. Wer also wissen will wie der User gerade sein Android-Phone hält kann das jetzt herausfinden:
Code: [AUSKLAPPEN] import android.view.*; class androidHelper{ static int getOrientation(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getOrientation(); } static int displayWidth(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getWidth(); } static int displayHeight(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getHeight(); } } In Monkey importieren und dann per Extern bekannt machen: Code: [AUSKLAPPEN] #if TARGET = "android" Function getOrientation:Int() = "androidHelper.getOrientation" Function displayWidth:Int() = "androidHelper.displayWidth" Function displayHeight:Int() = "androidHelper.displayHeight" #EndIf "getOrientation()" liefert eine 0 für Landscape und eine 1 für Portrait. Beachtet bitte dass ihr Eure meinSchönesSpiel.build/android/templates/AndroidManifest.xml noch ändern müsst: Sucht nach der Zeile in der ihr {SCREEN_ORIENTATION} findet und ersetzt {SCREEN_ORIENTATION} durch sensor. have fun! |
||
Farbfinsternis.tv |
![]() |
Farbfinsternis |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich wurde darauf aufmerksam gemacht dass "getOrientation" veraltet ist und habe darum "getRotation" eingebaut.
Code: [AUSKLAPPEN] import android.view.*; class androidHelper{ static int getRotation(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getRotation(); } static int displayWidth(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getWidth(); } static int displayHeight(){ android.view.Display display = ((WindowManager)MonkeyGame.activity.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getHeight(); } } In Monkey dann per Extern einbinden als: Code: [AUSKLAPPEN] #if TARGET = "android" Function getRotation:Int() = "androidHelper.getRotation" Function displayWidth:Int() = "androidHelper.displayWidth" Function displayHeight:Int() = "androidHelper.displayHeight" #EndIf Die Funktion "getRotation()" liefert einen Wet zwischen 0 und 3, diese Werte lauten: Code: [AUSKLAPPEN] Const ROTATION_0:Int = 0 Const ROTATION_90:Int = 1 Const ROTATION_180:Int = 2 const ROTATION_270:Int = 3 |
||
Farbfinsternis.tv |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group