本文整理匯總了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;
}
}