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


C# GameTime.GetElapsedSeconds方法代码示例

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


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

示例1: OnUpdate

		protected override void OnUpdate(GameTime gameTime, InputState istate)
		{
			if (!IsInViewport) return; // No drawing - no updating (state is frozen)

			internalTime += gameTime.GetElapsedSeconds();

			for (int i = ParticleCount - 1; i >= 0; i--)
			{
				particlePool[i].CurrentLifetime += gameTime.GetElapsedSeconds();
				if (particlePool[i].CurrentLifetime >= particlePool[i].MaxLifetime)
				{
					RemoveParticle(i);
				}
				else
				{
					particlePool[i].Position.X += particlePool[i].Velocity.X * gameTime.GetElapsedSeconds();
					particlePool[i].Position.Y += particlePool[i].Velocity.Y * gameTime.GetElapsedSeconds();
				}
			}

			timeSinceLastSpawn += gameTime.GetElapsedSeconds();
			while (timeSinceLastSpawn >= spawnDelay)
			{
				SpawnParticle();
				timeSinceLastSpawn -= spawnDelay;

				spawnDelay = _config.SpawnDelay;
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:29,代码来源:CPUParticleEmitter.cs

示例2: Update

		public void Update(GameTime gameTime)
		{
			// ReSharper disable once CompareOfFloatsByEqualityOperator
			if (ActualValue < TargetValue)
			{
				ActualValue += deltaSpeed * gameTime.GetElapsedSeconds();
				if (ActualValue > TargetValue) ActualValue = TargetValue;
			}
			else if (ActualValue > TargetValue)
			{
				ActualValue -= deltaSpeed * gameTime.GetElapsedSeconds();
				if (ActualValue < TargetValue) ActualValue = TargetValue;
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:14,代码来源:DeltaLimitedFloat.cs

示例3: DoUpdate

		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			if (IsOpening && FloatMath.IsNotOne(openingProgress))
			{
				bool hasOpened;
				openingProgress = FloatMath.LimitedInc(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 1f, out hasOpened);
				if (hasOpened)
				{
					IsOpening = false;
				}

				UpdateOpeningPosition();
			}
			else if (IsClosing)
			{
				bool hasClosed;
				openingProgress = FloatMath.LimitedDec(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 0f, out hasClosed);
				if (hasClosed)
				{
					Remove();
				}

				UpdateClosingPosition();
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:25,代码来源:HUDPauseMenuButton.cs

示例4: Update

		public void Update(GameTime gameTime, InputState istate)
		{
			timeSinceLastUpdate -= gameTime.GetElapsedSeconds();
			if (timeSinceLastUpdate <= 0)
			{
				timeSinceLastUpdate = updateInterval;

				Calculate(istate);
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:10,代码来源:AbstractFractionController.cs

示例5: Update

		public void Update(GameTime gameTime)
		{
			// ReSharper disable once CompareOfFloatsByEqualityOperator
			if (ActualValue != TargetValue)
			{
				var radSpeed = deltaSpeed * gameTime.GetElapsedSeconds();
				var diff = FloatMath.DiffModulo(ActualValue, TargetValue, modulo);

				ActualValue = FloatMath.Abs(diff) <= radSpeed ? TargetValue : FloatMath.AddRads(ActualValue, -FloatMath.Sign(diff) * radSpeed);
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:11,代码来源:DeltaLimitedModuloFloat.cs

示例6: UpdateDecay

		public void UpdateDecay(GameTime gameTime, bool first)
		{
			if (age < spawntime && spawntime > 0)
			{
				lifetime -= gameTime.GetElapsedSeconds();
				age += gameTime.GetElapsedSeconds();

				Decay = (float) (age / spawntime);
			}
			else if (lifetime < decaytime)
			{
				if (first)
				{
					lifetime -= gameTime.GetElapsedSeconds();
					age += gameTime.GetElapsedSeconds();

					Decay = (float) (lifetime / decaytime);
				}
				else
				{
					Decay = 1;
				}
			}
			else
			{
				lifetime -= gameTime.GetElapsedSeconds();
				age += gameTime.GetElapsedSeconds();

				Decay = 1;
			}

			if (lifetime < 0) IsAlive = false;

		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:34,代码来源:DebugTextDisplayLine.cs

示例7: CalculateSpeedOnDirection

        private Vector2 CalculateSpeedOnDirection(Direction direction, GameTime gameTime)
        {
            float time = gameTime.GetElapsedSeconds();
            Vector2 accel = direction.Acceleration;

            if (mobile.State == HitBoxState.Airborne)
            {
                accel.X /= MagicNumbers.AerialAccelerationPenaltyOnX;
            }

            Vector2 velocity = accel * direction * (float)Math.Pow(time, MagicNumbers.GameSpeedPower);
            return velocity;
        }
开发者ID:bevacqua,项目名称:MarianX,代码行数:13,代码来源:InterpolationCalculator.cs

示例8: CalculateInterpolation

        public virtual Vector2 CalculateInterpolation(GameTime gameTime)
        {
            Vector2 velocity = CalculateSpeedOnDirection(mobile.Direction, gameTime);
            Vector2 gravity = CalculateGravitySpeed(gameTime);

            Vector2 target = mobile.Speed + gravity + velocity;

            Vector2 afterHorizontal = HorizontalSpeedChanges(target, velocity);
            Vector2 afterVertical = VerticalSpeedChanges(afterHorizontal, gravity);

            mobile.Speed = ConstrainSpeed(afterVertical);

            float time = gameTime.GetElapsedSeconds();
            return mobile.Speed * time;
        }
开发者ID:bevacqua,项目名称:MarianX,代码行数:15,代码来源:InterpolationCalculator.cs

示例9: Update

		public void Update(GameTime gameTime, InputState istate)
		{
			Lifetime += gameTime.GetElapsedSeconds();

			for (int i = ActiveOperations.Count - 1; i >= 0; i--)
			{
				if (!ActiveOperations[i].Update(this, gameTime, istate))
				{
					ActiveOperations[i].OnEnd(this);
					ActiveOperations.RemoveAt(i);
				}
			}

			OnUpdate(gameTime, istate);
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:15,代码来源:GameEntity.cs

示例10: Update

        protected override void Update(GameTime gameTime)
        {
            var deltaTime = gameTime.GetElapsedSeconds();
            var keyboardState = Keyboard.GetState();
            var mouseState = Mouse.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
                Exit();

            if (_player != null && !_player.IsDestroyed)
            {
                const float acceleration = 5f;

                if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up))
                    _player.Accelerate(acceleration);

                if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down))
                    _player.Accelerate(-acceleration);

                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                    _player.Rotation -= deltaTime*3f;

                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                    _player.Rotation += deltaTime*3f;

                if (keyboardState.IsKeyDown(Keys.Space) || mouseState.LeftButton == ButtonState.Pressed)
                    _player.Fire();

                if (_previousMouseState.X != mouseState.X || _previousMouseState.Y != mouseState.Y)
                    _player.LookAt(_camera.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)));

                _camera.LookAt(_player.Position + _player.Velocity * 0.2f);
            }

            _entityManager.Update(gameTime);

            CheckCollisions();

            _previousMouseState = mouseState;


            _guiManager.Update(gameTime);
            base.Update(gameTime);
        }
开发者ID:detuur,项目名称:MonoGame.Extended,代码行数:44,代码来源:GameMain.cs

示例11: UpdateDrag

		private void UpdateDrag(GameTime gameTime, InputState istate)
		{
			var delta = istate.PointerPosition - mouseStartPos;

			Screen.MapOffsetX = startOffset.X + delta.X;
			Screen.MapOffsetY = startOffset.Y + delta.Y;

			CalculateOOB();

			lastMousePosTimer += gameTime.GetElapsedSeconds();
			if (lastMousePosTimer > DRAGSPEED_RESOLUTION)
			{
				dragSpeed = (istate.PointerPosition - lastMousePos) / lastMousePosTimer;

				//Debug.WriteLine(dragSpeed);

				lastMousePosTimer = 0f;
				lastMousePos = istate.PointerPosition;
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:20,代码来源:WorldMapDragAgent.cs

示例12: UpdateRestDrag

		private void UpdateRestDrag(GameTime gameTime)
		{
			float dragX = dragSpeed.X + outOfBoundsForce.X;
			float dragY = dragSpeed.Y + outOfBoundsForce.Y;
			
			Screen.MapOffsetX = Screen.MapOffsetX + dragX * gameTime.GetElapsedSeconds();
			Screen.MapOffsetY = Screen.MapOffsetY + dragY * gameTime.GetElapsedSeconds();

			CalculateOOB();

			dragSpeed -= dragSpeed * FRICTION * gameTime.GetElapsedSeconds();

			if (dragSpeed.LengthSquared() < SPEED_MIN * SPEED_MIN)
			{
				dragSpeed = Vector2.Zero;
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:17,代码来源:WorldMapDragAgent.cs

示例13: UpdateClosing

		private void UpdateClosing(GameTime gameTime)
		{
			bool finished;
			openingProgress = FloatMath.LimitedDec(openingProgress, gameTime.GetElapsedSeconds() * OPENING_ANIMATION_CLOSINGSPEED, 0f, out finished);

			for (int i = 0; i < 5; i++)
			{
				speedButtons[i].RelativePosition = RelativePosition + OPENING_VECTORS[i] * openingProgress;
			}

			if (finished)
			{
				foreach (var btn in speedButtons)
				{
					btn.Remove();

					btn.IsOpened = false;
				}
				speedButtons = null;
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:21,代码来源:HUDSpeedBaseButton.cs

示例14: UpdateOpening

		private void UpdateOpening(GameTime gameTime, bool force)
		{
			bool finished;
			openingProgress = FloatMath.LimitedInc(openingProgress, gameTime.GetElapsedSeconds() * OPENING_ANIMATION_TOTALSPEED, 1f, out finished);

			if (force)
			{
				openingProgress = 1f;
				finished = true;
			}

			for (int i = 0; i < 5; i++)
			{
				var progress = FloatMath.LimitedDec(openingProgress, i * OPENING_ANIMATION_DELAY, 0f) / OPENING_ANIMATION_SINGLESPEED;

				speedButtons[i].RelativePosition = RelativePosition + OPENING_VECTORS[i] * FloatMath.FunctionEaseOutElastic(progress);
			}

			if (finished)
			{
				foreach (var btn in speedButtons)
				{
					btn.IsOpened = true;
				}
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:26,代码来源:HUDSpeedBaseButton.cs

示例15: DoUpdate

		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			rotation = FloatMath.IncModulo(rotation, gameTime.GetElapsedSeconds() * HAND_ANIMATION_SPEED * this.GDHUD().GDOwner.GameSpeed, FloatMath.TAU);

			int choosen = -1;

			if (isOpened && isDragging)
			{
				var center = new Vector2(Position.X + Size.Width / 2f, Position.Y + Size.Height / 2f);
				
				var delta = istate.PointerPosition - center;
				if (delta.LengthSquared() >= DRAG_MINIMUMDISTANCE * DRAG_MINIMUMDISTANCE)
				{
					var angle = delta.ToAngle();

					if (angle > -FloatMath.PI && angle < FloatMath.PI / 16f)
						choosen = 0;
					else if (angle > FloatMath.PI / 16f && angle < 3 * FloatMath.PI / 16f)
						choosen = 1;
					else if (angle > 3 * FloatMath.PI / 16f && angle < 5 * FloatMath.PI / 16f)
						choosen = 2;
					else if (angle > 5 * FloatMath.PI / 16f && angle < 7 * FloatMath.PI / 16f)
						choosen = 3;
					else if (angle > 7 * FloatMath.PI / 16f && angle < FloatMath.PI)
						choosen = 4;
				}

				if (istate.IsDown)
				{
					for (int i = 0; i < 5; i++)
					{
						speedButtons[i].Highlighted = (i == choosen);
					}
				}
				else
				{
					if (choosen != -1)
					{
						speedButtons[choosen].Click();
					}

					isDragging = false;
				}
			}

			if (isOpened && FloatMath.IsNotOne(openingProgress))
			{
				UpdateOpening(gameTime, choosen != -1);
			}
			else if (!isOpened && FloatMath.IsNotZero(openingProgress))
			{
				UpdateClosing(gameTime);
			}
		}
开发者ID:Mikescher,项目名称:GridDominance,代码行数:54,代码来源:HUDSpeedBaseButton.cs


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