Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            if (_pendingCoreGame != null && _coreGame == null)
            {
                _coreGame = _pendingCoreGame;
                _coreGame.AssignHost(this);

                if (_shouldLoadContentOnDelayedGame)
                {
                    _coreGame.LoadContent();
                }
            }

            if (_coreGame != null)
            {
#if PLATFORM_WINDOWS
                if (Window != null)
                {
                    if (_windowWidth != Window.ClientBounds.Width ||
                        _windowHeight != Window.ClientBounds.Height)
                    {
                        OnClientSizeChanged(this, EventArgs.Empty);
                    }
                }
#endif

                _coreGame.Update(gameTime);
                return;
            }
        }
        public void Update(TimeSpan totalTimeSpan, TimeSpan elapsedTimeSpan)
        {
            if (!_hasLoadedContent)
            {
                _coreGame.AssignHost(this);
                _coreGame.LoadContent();
                _hasLoadedContent = true;
            }

            _coreGame.Update(new GameTime(totalTimeSpan, elapsedTimeSpan));
        }
Beispiel #3
0
        protected override void LoadContent()
        {
            GraphicsDevice.DeviceLost += (sender, e) =>
            {
                _coreGame?.DeviceLost();
            };
            GraphicsDevice.DeviceReset += (sender, e) =>
            {
                _coreGame?.DeviceReset();
            };
            GraphicsDevice.DeviceResetting += (sender, e) =>
            {
                _coreGame?.DeviceResetting();
            };
            GraphicsDevice.ResourceCreated += (sender, e) =>
            {
                _coreGame?.ResourceCreated(e.Resource);
            };
            GraphicsDevice.ResourceDestroyed += (sender, e) =>
            {
                _coreGame?.ResourceDestroyed(e.Name, e.Tag);
            };

            // Construct a platform-independent game window.
            ProtogameWindow = ConstructGameWindow();

#if PLATFORM_ANDROID
            // On Android, disable viewport / backbuffer scaling because we expect games
            // to make use of the full display area.
            this.GraphicsDeviceManager.IsFullScreen = true;
            this.GraphicsDeviceManager.PreferredBackBufferHeight = this.Window.ClientBounds.Height;
            this.GraphicsDeviceManager.PreferredBackBufferWidth  = this.Window.ClientBounds.Width;
#endif

#if PLATFORM_WINDOWS
            // Register for the window resize event so we can scale
            // the window correctly.
            Window.ClientSizeChanged += OnClientSizeChanged;

            // Register for the window close event so we can dispatch
            // it correctly.
            var form = System.Windows.Forms.Control.FromHandle(Window.Handle) as System.Windows.Forms.Form;
            if (form != null)
            {
                form.FormClosing += (sender, args) =>
                {
                    bool cancel = false;
                    _coreGame?.CloseRequested(out cancel);

                    if (cancel)
                    {
                        args.Cancel = true;
                    }
                };
            }
#endif

            if (_coreGame != null)
            {
                _coreGame.LoadContent();
                return;
            }

            _shouldLoadContentOnDelayedGame = true;

            _splashSpriteBatch = new SpriteBatch(GraphicsDevice);

#if PLATFORM_ANDROID
            try
            {
                var layout       = _gameActivity.Window.DecorView.FindViewById(Android.Resource.Id.Content);
                var backgroundId = _gameActivity.Resources.GetIdentifier("background", "drawable", Android.App.Application.Context.PackageName);
                _splash = Texture2D.FromStream(GraphicsDevice, Android.Graphics.BitmapFactory.DecodeResource(_gameActivity.Resources, backgroundId));
            }
            catch
            {
                // Setting background is optional.
            }
#endif
        }