本文整理汇总了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;
}
}
示例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;
}
}
示例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();
}
}
示例4: Update
public void Update(GameTime gameTime, InputState istate)
{
timeSinceLastUpdate -= gameTime.GetElapsedSeconds();
if (timeSinceLastUpdate <= 0)
{
timeSinceLastUpdate = updateInterval;
Calculate(istate);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
}
示例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);
}
}