當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。