Esempio n. 1
0
        protected override void OnDraw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            float elapsedSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            this.background.Draw(spriteBatch);
            this.entityWorld.Draw(elapsedSeconds, spriteBatch);
            this.particleEngine.Draw(spriteBatch);

            //if (MouseManager.IsLeftButtonDown())
            //{
            //    spriteBatch.DrawCircle(new Circle(this.entityCamera.ScreenToWorld(MouseManager.GetMouseCursorPosition() * GameConfig.ScreenToWorldScale), 100), Color.Pink, 3);
            //}

            if (Kadro.Input.KeyboardInput.IsKeyDown(Keys.B))
            {
                Vector2 position = this.Camera.ViewToWorld(WindowSettings.ScreenToView(MouseInput.GetCursorPosition().ToVector2()));
                spriteBatch.DrawCircle(position, 2, Color.Red, 1);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            ////if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            ////    Exit();

            this.performanceCounter.BeginUpdate();

            base.Update(gameTime);

            this.performanceCounter.Update(gameTime);

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F12))
            {
                WindowSettings.SetBorderless(this.isBorderless = !this.isBorderless);
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.Up) || Kadro.Input.KeyboardInput.OnKeyUp(Keys.Left))
            {
                this.sceneManager.TabPrevious();
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.Down) || Kadro.Input.KeyboardInput.OnKeyUp(Keys.Right))
            {
                this.sceneManager.TabNext();
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F3))
            {
                this.showPerformanceStats = !this.showPerformanceStats;
            }

            if (!(this.renderTarget.Width == WindowSettings.RenderArea.Width && this.renderTarget.Height == WindowSettings.RenderArea.Height))
            {
                this.renderTarget.Dispose();
                this.renderTarget = new RenderTarget2D(this.GraphicsDevice, WindowSettings.RenderArea.Width, WindowSettings.RenderArea.Height);
            }

            this.sceneManager.Update(gameTime);
            this.perfLabel.Update();
#if DEBUG
            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F1))
            {
                if (this.debugListbox.IsVisible)
                {
                    this.debugListbox.Hide();
                }
                else
                {
                    this.debugListbox.Show();
                }
            }

            this.debugListbox.Update();

            Point   cursor   = MouseInput.GetCursorPosition();
            Vector2 viewPos  = WindowSettings.ScreenToView(cursor.ToVector2());
            Vector2 worldPos = GameScene.ActiveScene.ViewToWorld(viewPos);
            this.mousePos.TextBlock.Text = $"MousePos: {cursor}\nViewPos: {viewPos}\nWorldPos: {worldPos}";

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F5))
            {
                if (this.mousePos.IsVisible)
                {
                    this.mousePos.SetVisible(false);
                }
                else
                {
                    this.mousePos.SetVisible(true);
                }
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.L) && this.networkManager.IsActive)
            {
                this.networkManager.SetDebugLatency(0.05f, 0.02f, 0.0f);  // 50ms, 20ms
                this.networkManager.EnableDebugLatency(!this.networkManager.DebugLatency);
            }
#endif
            GameScene.ActiveScene.Update(gameTime);

            this.performanceCounter.EndUpdate();

            if (this.showPerformanceStats)
            {
                this.ShowPerformanceOnWindowTitle();
            }
        }