当前位置: 首页>>代码示例>>C#>>正文


C# GameTime.GetDeltaTime方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.GameTime.GetDeltaTime方法的典型用法代码示例。如果您正苦于以下问题:C# GameTime.GetDeltaTime方法的具体用法?C# GameTime.GetDeltaTime怎么用?C# GameTime.GetDeltaTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.GameTime的用法示例。


在下文中一共展示了GameTime.GetDeltaTime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        public override void Update(GameTime gameTime)
        {
            Velocity = new Vector3(Velocity.X, Velocity.Y - Physics.Physics.GravityAcceleration, Velocity.Z);
            Position += Velocity*gameTime.GetDeltaTime();

            base.Update(gameTime);
        }
开发者ID:ruicaridade,项目名称:IP3D,代码行数:7,代码来源:Cannonball.cs

示例2: Update

        /// <summary>
        /// JigLibX の PhysicsSystem のインテグレーションを実行します。
        /// </summary>
        /// <param name="gameTime">前回の Update が呼び出されてからの経過時間。</param>
        /// <remarks>
        /// インテグレーション実行の前後では登録された IIntegrationListener が呼び出されます。
        /// </remarks>
        public override void Update(GameTime gameTime)
        {
            if (IntegrationListeners.Count != 0)
            {
                foreach (var listener in integrationListeners)
                {
                    listener.PreIntegration(gameTime);
                }
            }

            physicsSystem.Integrate(gameTime.GetDeltaTime());

            if (IntegrationListeners.Count != 0)
            {
                foreach (var listener in integrationListeners)
                {
                    listener.PostIntegration(gameTime);
                }
            }
        }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:27,代码来源:JigLibComponent.cs

示例3: Update

        /// <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)
        {
            IsActive = base.IsActive;
            if (!IsActive) return;

            if (Input.IsKeyPressed(Keys.F1))
            {
                Debugging = !Debugging;
                DebugHud.DebugStringPanels[0].Get("toggle_debug").Text = "Debug Mode (F1): " + Debugging;
            }

            if (Input.IsKeyPressed(Keys.P))
            {
                spectating = !spectating;
                DebugHud.DebugStringPanels[0].Get("spectate_info").Text = "Spectator Camera (P): " + spectating;
            }

            OnGameUpdate(gameTime);

            MainCamera.Update(gameTime);
            tank.Update(gameTime, map);
            MainCamera.Position = new Vector3(tank.Position.X - tank.Front.X * 8.0f, tank.Position.Y + 8.0f,
                tank.Position.Z - tank.Front.Z * 8.0f);

            SpectatorCamera.Update(gameTime);
            aiTank.Update(gameTime, map);
            SpectatorCamera.Position = new Vector3(aiTank.Position.X - aiTank.Front.X * 8.0f, aiTank.Position.Y + 8.0f,
                aiTank.Position.Z - aiTank.Front.Z * 8.0f);

            float camAngle = tank.Yaw + 90.0f;
            if (camAngle > 360.0f)
            {
                camAngle = camAngle - 360.0f;
            }

            MainCamera.Yaw = camAngle;

            camAngle = aiTank.Yaw + 90.0f;
            if (camAngle > 360.0f)
            {
                camAngle = camAngle - 360.0f;
            }

            SpectatorCamera.Yaw = camAngle;

            rainEmitter.Update(gameTime);

            dustEmitter.Start = tank.Position - tank.Right * 2 - tank.Front * 3.5f;
            dustEmitter.End = tank.Position + tank.Right * 2 - tank.Front * 3.5f;
            dustEmitter.Velocity = new Vector3(10.0f * -tank.Front.X,
                25.0f, 10.0f * -tank.Front.Z);
            dustEmitter.Interval = tank.IsMoving ? 0.01f : float.MaxValue;
            dustEmitter.Update(gameTime);

            effect.Projection = MainCamera.Projection;
            effect.View = MainCamera.View;

            DebugHud.DebugStringPanels[0].Get("fps").Text = "FPS: " + gameTime.GetFramesPerSecond();
            DebugHud.DebugStringPanels[0].Get("delta_time").Text = "Delta Time: " + gameTime.GetDeltaTime();

            if (Input.IsKeyPressed(Keys.Escape))
            {
                Exit();
            }

            base.Update(gameTime);
        }
开发者ID:ruicaridade,项目名称:IP3D,代码行数:72,代码来源:TankSim.cs

示例4: Update

 public override void Update(GameTime gameTime)
 {
     var sceneSettings = ControllerContext.Scene.SceneSettings;
     sceneSettings.Time += gameTime.GetDeltaTime() * sceneSettings.TimeScale;
 }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:5,代码来源:WorldTimeController.cs

示例5: Update

        public override void Update(GameTime gameTime)
        {
            if (!camera.Active) return;

            var dt = gameTime.GetDeltaTime();

            var newPosition = camera.Position;
            var newOrientation = camera.Orientation;

            var deltaRotation = new Vector2();

            var mouse = InputDevice.GetMouse();
            if (mouse.IsMouseMoved)
            {
                deltaRotation.X += mouse.DeltaX;
                deltaRotation.Y += mouse.DeltaY;
                mouse.ResetPosition();
            }

            var pad = InputDevice.GetGamePad(PlayerIndex);
            {
                const float padRotationAmount = 10.0f;

                var stickPosition = pad.CurrentState.ThumbSticks.Right;
                deltaRotation.X += stickPosition.X * padRotationAmount;
                deltaRotation.Y += -stickPosition.Y * padRotationAmount;
            }

            {
                float yaw;
                float pitch;
                float roll;
                camera.Orientation.ToYawPitchRoll(out yaw, out pitch, out roll);

                yaw -= RotationVelocity * deltaRotation.X * dt % (2 * MathHelper.Pi);
                pitch -= RotationVelocity * deltaRotation.Y * dt;

                if (MathHelper.PiOver2 < pitch)
                {
                    pitch = MathHelper.PiOver2;
                }
                else if (pitch < -MathHelper.PiOver2)
                {
                    pitch = -MathHelper.PiOver2;
                }

                newOrientation = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
            }

            var moveDirection = new Vector3(0, 0, 0);

            var keyboard = InputDevice.GetKeybord(PlayerIndex);
            if (keyboard.IsKeyDown(Keys.W))
            {
                moveDirection.Z = -1;
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                moveDirection.Z = 1;
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                moveDirection.X = 1;
            }
            if (keyboard.IsKeyDown(Keys.A))
            {
                moveDirection.X = -1;
            }
            if (keyboard.IsKeyDown(Keys.Q))
            {
                moveDirection.Y = 1;
            }
            if (keyboard.IsKeyDown(Keys.Z))
            {
                moveDirection.Y = -1;
            }

            {
                var delta = pad.CurrentState.ThumbSticks.Left;
                moveDirection.X += delta.X;
                moveDirection.Z += -delta.Y;

                if (pad.IsButtonDown(Buttons.LeftShoulder))
                {
                    moveDirection.Y += 1;
                }
                if (pad.IsButtonDown(Buttons.RightShoulder))
                {
                    moveDirection.Y += -1;
                }
            }

            if (!moveDirection.IsZero())
            {
                moveDirection.Normalize();
                newPosition += MoveVelocity * dt * Vector3.Transform(moveDirection, newOrientation);
            }

            camera.Position = newPosition;
            camera.Orientation = newOrientation;
//.........这里部分代码省略.........
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:101,代码来源:CameraController.cs

示例6: UpdateCameraByThirdPersonPov

        void UpdateCameraByThirdPersonPov(GameTime gameTime)
        {
            //
            // Decide the offset vector from inputs
            //
            float deltaYaw = 0;
            float deltaPitch = 0;

            var keyboard = InputDevice.GetKeybord(PlayerIndex);
            if (keyboard.IsKeyDown(Keys.Up))
            {
                deltaPitch += 1;
            }
            if (keyboard.IsKeyDown(Keys.Down))
            {
                deltaPitch -= 1;
            }
            if (keyboard.IsKeyDown(Keys.Left))
            {
                deltaYaw += 1;
            }
            if (keyboard.IsKeyDown(Keys.Right))
            {
                deltaYaw -= 1;
            }

            var pad = InputDevice.GetGamePad(PlayerIndex);
            {
                var stickPosition = pad.CurrentState.ThumbSticks.Right;
                deltaYaw += -stickPosition.X;
                deltaPitch += stickPosition.Y;
            }

            float deltaTime = gameTime.GetDeltaTime();

            //const float amount = 0.05f;
            const float amount = 1.0f;
            deltaYaw *= amount * deltaTime;
            deltaPitch *= amount * deltaTime;

            // rotate the offset vector around Y axis
            if (deltaYaw != 0)
            {
                Matrix rotation;
                Matrix.CreateRotationY(deltaYaw, out rotation);
                Vector3.Transform(ref offsetVector, ref rotation, out offsetVector);
            }
            // rotate the offset vector around the right vector of the camera
            if (deltaPitch != 0)
            {
                Vector3 pitchAxis;
                Vector3 up = Vector3.Up;
                Vector3.Cross(ref offsetVector, ref up, out pitchAxis);

                Matrix rotation;
                Matrix.CreateFromAxisAngle(ref pitchAxis, deltaPitch, out rotation);
                Vector3.Transform(ref offsetVector, ref rotation, out offsetVector);
            }

            //
            // Manual zoom
            //
            if (keyboard.IsKeyDown(Keys.PageUp) && keyboard.IsKeyDown(Keys.PageDown))
            {
                cameraDistance = InitialOffsetDistance;
            }
            else
            {
                if (keyboard.IsKeyDown(Keys.PageUp))
                {
                    cameraDistance -= ManualZoomVelocity * gameTime.GetDeltaTime();
                    // reset auto zoom
                    oldAdjustedCameraDistance = cameraDistance;
                }
                if (keyboard.IsKeyDown(Keys.PageDown))
                {
                    cameraDistance += ManualZoomVelocity * gameTime.GetDeltaTime();
                }
            }
            // clamp [ZoomMinCameraDistance, MaxCameraDistance]
            cameraDistance = MathExtension.Clamp(cameraDistance, ZoomMinCameraDistance, MaxCameraDistance);

            //
            // try to adjust the offset distance with models blocking the ray from the camera to the actor
            //
            float adjustedOffsetDistance = CalculateAdjustedOffsetDistance(ref character.Position);

            //
            // Auto zoom
            //
            // interpolate from the adjusted offset distance to the desired offset one
            //
            if (cameraDistance <= adjustedOffsetDistance)
            {
                if (oldAdjustedCameraDistance < cameraDistance)
                {
                    adjustedOffsetDistance = oldAdjustedCameraDistance + AutoZoomVelocity * deltaTime;
                    adjustedOffsetDistance = MathHelper.Min(adjustedOffsetDistance, cameraDistance);
                    oldAdjustedCameraDistance = adjustedOffsetDistance;
                }
//.........这里部分代码省略.........
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:101,代码来源:CharacterCameraController.cs

示例7: UpdateCameraByFirstPersonPov

        void UpdateCameraByFirstPersonPov(GameTime gameTime)
        {
            float deltaYaw = 0;
            float deltaPitch = 0;

            //
            // Decide the offset vector from inputs
            //
            var keyboard = InputDevice.GetKeybord(PlayerIndex);
            if (keyboard.IsKeyDown(Keys.Up))
            {
                deltaPitch += 1;
            }
            if (keyboard.IsKeyDown(Keys.Down))
            {
                deltaPitch -= 1;
            }
            if (keyboard.IsKeyDown(Keys.Left))
            {
                deltaYaw += 1;
            }
            if (keyboard.IsKeyDown(Keys.Right))
            {
                deltaYaw -= 1;
            }

            var pad = InputDevice.GetGamePad(PlayerIndex);
            {
                var delta = pad.CurrentState.ThumbSticks.Right;
                deltaYaw += -delta.X;
                deltaPitch += delta.Y;
            }

            float deltaTime = gameTime.GetDeltaTime();

            const float amount = 5.0f;
            if (deltaYaw != 0)
            {
                deltaYaw *= amount * deltaTime;
                firstPersonCameraDeltaYaw += deltaYaw;
                firstPersonCameraDeltaYaw = MathExtension.Clamp(
                    firstPersonCameraDeltaYaw,
                    -MathHelper.PiOver2,
                    MathHelper.PiOver2);
            }
            else
            {
                if (firstPersonCameraDeltaYaw < 0)
                {
                    firstPersonCameraDeltaYaw += amount * deltaTime;
                    firstPersonCameraDeltaYaw = MathHelper.Min(firstPersonCameraDeltaYaw, 0);
                }
                else if (0 < firstPersonCameraDeltaYaw)
                {
                    firstPersonCameraDeltaYaw -= amount * deltaTime;
                    firstPersonCameraDeltaYaw = MathHelper.Max(0, firstPersonCameraDeltaYaw);
                }
            }

            if (deltaPitch != 0)
            {
                deltaPitch *= amount * deltaTime;
                firstPersonCameraDeltaPitch += deltaPitch;
                firstPersonCameraDeltaPitch = MathExtension.Clamp(
                    firstPersonCameraDeltaPitch,
                    -MathHelper.PiOver2,
                    MathHelper.PiOver2);
            }
            else
            {
                if (firstPersonCameraDeltaPitch < 0)
                {
                    firstPersonCameraDeltaPitch += amount * deltaTime;
                    firstPersonCameraDeltaPitch = MathHelper.Min(firstPersonCameraDeltaPitch, 0);
                }
                else if (0 < firstPersonCameraDeltaPitch)
                {
                    firstPersonCameraDeltaPitch -= amount * deltaTime;
                    firstPersonCameraDeltaPitch = MathHelper.Max(0, firstPersonCameraDeltaPitch);
                }
            }

            // calculate the relative orientation from the actor orientation
            float actorYaw = character.Orientation.GetYaw();
            float actorPitch = 0;
            float yaw = actorYaw + firstPersonCameraDeltaYaw;
            float pitch = actorPitch + firstPersonCameraDeltaPitch;

            // set the camera orientation
            Matrix.CreateFromYawPitchRoll(yaw, pitch, 0, out camera.Orientation);

            float adjustedOffsetDistance = 0;
            if (0 < oldAdjustedCameraDistance)
            {
                adjustedOffsetDistance = oldAdjustedCameraDistance - AutoZoomVelocity * deltaTime;
                adjustedOffsetDistance = MathHelper.Max(adjustedOffsetDistance, 0);
                oldAdjustedCameraDistance = adjustedOffsetDistance;
            }
            else
            {
//.........这里部分代码省略.........
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:101,代码来源:CharacterCameraController.cs

示例8: UpdateActorByFirstPersonPov

        void UpdateActorByFirstPersonPov(GameTime gameTime)
        {
            float deltaYaw = 0;

            #region Control the orientation for the keyboard

            var keyboard = InputDevice.GetKeybord(PlayerIndex);
            if (keyboard.IsKeyDown(Keys.A))
            {
                deltaYaw += 1.0f;
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                deltaYaw += -1.0f;
            }

            #endregion

            #region Control the orientation for the gamepad

            var pad = InputDevice.GetGamePad(PlayerIndex);
            {
                var stickPosition = pad.CurrentState.ThumbSticks.Left;
                deltaYaw += -stickPosition.X;
            }

            #endregion

            #region Decide the orientation

            // calculate and set the new orientation
            if (deltaYaw != 0)
            {
                float newYaw = character.Orientation.GetYaw() + deltaYaw * gameTime.GetDeltaTime();
                Matrix.CreateRotationY(newYaw, out character.Orientation);
            }

            #endregion

            // 重力加速度。
            Vector3 gravity;
            character.RigidBody.GetGravity(out gravity);

            // 進行方向ベクトル。
            var moveDirection = Vector3.Zero;
            float moveVelocityFactor = 1.0f;

            #region Control the direction for the keyboard

            if (keyboard.IsKeyDown(Keys.W))
            {
                moveDirection.Z += -1;
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                moveDirection.Z += 1;
            }

            #endregion

            #region Control the direction for the gamepad

            {
                var stickPosition = pad.CurrentState.ThumbSticks.Left;
                moveDirection.Z += -stickPosition.Y;
                var degree = Math.Abs(stickPosition.Y);
                if (degree != 0)
                {
                    moveVelocityFactor = degree;
                }
            }

            #endregion

            // rotate the move direction
            Vector3.Transform(ref moveDirection, ref character.Orientation, out moveDirection);
            Vector3Extension.NormalizeSafe(ref moveDirection, out moveDirection);

            // 重力方向に対して衝突があるかどうかを判定します。
            bool isStanding = character.CollisionBounds.IsCollidedForDirection(ref gravity);

            #region Control the autorun

            if (keyboard.IsKeyPressed(Keys.R) ||
                keyboard.IsKeyPressed(Keys.NumPad7) ||
                pad.IsButtonPressed(Buttons.LeftShoulder))
            {
                if (!autorunActivated)
                {
                    // try to activate autorun
                    if (!moveDirection.IsZero() && isStanding)
                    {
                        autorunActivated = true;
                    }
                }
                else
                {
                    autorunActivated = false;
                }
            }
//.........这里部分代码省略.........
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:101,代码来源:CharacterCameraController.cs

示例9: Update

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Input.IsKeyDown(Keys.W))
            {
                MoveForward(WalkSpeed, gameTime.GetDeltaTime());
            }
            if (Input.IsKeyDown(Keys.S))
            {
                MoveForward(-WalkSpeed, gameTime.GetDeltaTime());
            }
            if (Input.IsKeyDown(Keys.A))
            {
                MoveRight(StrafeSpeed, gameTime.GetDeltaTime());
            }
            if (Input.IsKeyDown(Keys.D))
            {
                MoveRight(-StrafeSpeed, gameTime.GetDeltaTime());
            }

            mouseState = Mouse.GetState();

            mousePosition = new Vector2(mouseState.Position.X, mouseState.Position.Y);
            Yaw -= (viewport.GetCenter().X - mousePosition.X) * Sensitivity;
            Pitch += (viewport.GetCenter().Y - mousePosition.Y)*Sensitivity;
            Pitch = MathHelper.Clamp(Pitch, -89.0f, 89.0f);

            Mouse.SetPosition((int)Math.Round(viewport.GetCenter().X), (int)Math.Round(viewport.GetCenter().Y));

            UpdateMatrices();
        }
开发者ID:ruicaridade,项目名称:IP3D,代码行数:32,代码来源:FirstPersonCamera.cs

示例10: Update

        public override void Update(GameTime gameTime)
        {
            var dt = gameTime.GetDeltaTime();
            const float OpenSpeed = 8.0f;
            const float CloseSpeed = 8.0f;

            switch (state)
            {
                case DebugCommandState.Closed:
                    if (InputDevice.GetKeybord(PlayerIndex.One).IsKeyDown(Keys.Tab))
                    {
                        state = DebugCommandState.Opening;

                        if (Activated != null)
                        {
                            Activated(this, EventArgs.Empty);
                        }
                    }
                    break;
                case DebugCommandState.Opening:
                    stateTransition += dt * OpenSpeed;
                    if (stateTransition > 1.0f)
                    {
                        stateTransition = 1.0f;
                        state = DebugCommandState.Opened;
                    }
                    break;
                case DebugCommandState.Opened:
                    ProcessKeyInputs(dt);
                    break;
                case DebugCommandState.Closing:
                    stateTransition -= dt * CloseSpeed;
                    if (stateTransition < 0.0f)
                    {
                        stateTransition = 0.0f;
                        state = DebugCommandState.Closed;

                        if (Deactivated != null)
                        {
                            Deactivated(this, EventArgs.Empty);
                        }
                    }
                    break;
            }
        }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:45,代码来源:DebugConsoleComponent.cs


注:本文中的Microsoft.Xna.Framework.GameTime.GetDeltaTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。