本文整理汇总了C#中Microsoft.Xna.Framework.GameTime.ElapsedSeconds方法的典型用法代码示例。如果您正苦于以下问题:C# GameTime.ElapsedSeconds方法的具体用法?C# GameTime.ElapsedSeconds怎么用?C# GameTime.ElapsedSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.GameTime
的用法示例。
在下文中一共展示了GameTime.ElapsedSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public static void Update( GameTime gt ) {
Camera camera = Utility.Camera;
InputState inputState = Utility.InputState;
float elapsedTime = gt.ElapsedSeconds();
Vector2 lookDelta = Vector2.Zero;
lookDelta = inputState.MousePositionDelta;
if( lookDelta != Vector2.Zero ) {
lookDelta.Normalize();
}
if( lookDelta == Vector2.Zero ) {
lookDelta = new Vector2(
inputState.IsKeyDown( Keys.Right ) ? 1 : inputState.IsKeyDown( Keys.Left ) ? -1 : 0,
inputState.IsKeyDown( Keys.Up ) ? 1 : inputState.IsKeyDown( Keys.Down ) ? -1 : 0 );
}
float rotateSpeed = elapsedTime * 2.0f;
float moveSpeed = 0;
if( inputState.IsKeyDown( Keys.LeftShift ) ) {
moveSpeed = elapsedTime * 100.0f * ( inputState.IsKeyDown( Keys.LeftShift ) ? 10.0f : 1.0f );
} else {
moveSpeed = elapsedTime * 100.0f * 1.0f;
}
camera.Direction = Vector3.TransformNormal( camera.Direction, Matrix.CreateRotationY( lookDelta.X * -rotateSpeed ) );
camera.Direction = Vector3.TransformNormal( camera.Direction, Matrix.CreateFromAxisAngle( Vector3.Cross( Vector3.Up, camera.Direction ), -lookDelta.Y * rotateSpeed ) );
Vector3 moveVec = Vector3.Zero;
if( inputState.IsKeyDown( Keys.W ) || inputState.IsKeyDown( Keys.Up ) ) {
moveVec += camera.Direction;
}
if( inputState.IsKeyDown( Keys.S ) || inputState.IsKeyDown( Keys.Down ) ) {
moveVec -= camera.Direction;
}
if( inputState.IsKeyDown( Keys.A ) || inputState.IsKeyDown( Keys.Right ) ) {
moveVec += Vector3.Cross( Vector3.Up, camera.Direction );
}
if( inputState.IsKeyDown( Keys.D ) || inputState.IsKeyDown( Keys.Left ) ) {
moveVec -= Vector3.Cross( Vector3.Up, camera.Direction );
}
if( moveVec.Length() > 0.0f )
moveVec.Normalize();
Utility.Camera.Position += moveVec * moveSpeed;
if( Utility.Game.IsActive ) {
Rectangle windowBounds = Utility.Game.Window.ClientBounds;
Vector2 windowCenter = new Vector2( (float)( windowBounds.Width / 2 ), (float)( windowBounds.Height / 2 ) );
inputState.MousePosition = windowCenter;
}
}