Beispiel #1
0
 public AndroidGameView(Context context, AndroidGameWindow gameWindow, Game game)
     : base(context)
 {
     _gameWindow   = gameWindow;
     _game         = game;
     _touchManager = new AndroidTouchEventManager(gameWindow);
     Init();
 }
Beispiel #2
0
        public AndroidGamePlatform(Game game) : base(game)
        {
            Game.Activity.Game           = Game;
            AndroidGameActivity.Paused  += Activity_Paused;
            AndroidGameActivity.Resumed += Activity_Resumed;

            _gameWindow = new AndroidGameWindow(Game.Activity, game);
            Window      = _gameWindow;

            try
            {
                OpenALSoundController soundControllerInstance = OpenALSoundController.GetInstance;
            }
            catch (DllNotFoundException ex)
            {
                throw new NoAudioHardwareException("Failed to init OpenALSoundController", ex);
            }
        }
Beispiel #3
0
        public override void OnOrientationChanged(int orientation)
        {
            if (orientation == OrientationEventListener.OrientationUnknown)
            {
                return;
            }

            // Avoid changing orientation whilst the screen is locked
            if (ScreenReceiver.ScreenLocked)
            {
                return;
            }

            // Check if screen orientation is locked by user: if it's locked, do not change orientation.
            try
            {
                if (Settings.System.GetInt(Application.Context.ContentResolver, "accelerometer_rotation") == 0)
                {
                    return;
                }
            }
            catch (Settings.SettingNotFoundException)
            {
                // Do nothing (or log warning?). In case android API or Xamarin do not support this Android system property.
            }

            var disporientation = AndroidCompatibility.GetAbsoluteOrientation(orientation);

            // Only auto-rotate if target orientation is supported and not current
            AndroidGameWindow gameWindow = (AndroidGameWindow)Game.Instance.Window;

            if ((gameWindow.GetEffectiveSupportedOrientations() & disporientation) != 0 &&
                disporientation != gameWindow.CurrentOrientation)
            {
                gameWindow.SetOrientation(disporientation, true);
            }
        }