C# 使用时间平衡游戏更新
我正在尝试将我的XNA游戏的FPS上限设置为90,现在设置好了,游戏以惊人的速度运行,即使我将速度乘以C# 使用时间平衡游戏更新,c#,xna,C#,Xna,我正在尝试将我的XNA游戏的FPS上限设置为90,现在设置好了,游戏以惊人的速度运行,即使我将速度乘以(float)gameTime.ElapsedGameTime.totalMillimes 你能帮我弄清楚它为什么不起作用吗?我看到其他人都很好,但我的不行 这就是我的Player类(足够大): 更新方法: public void Update(GameTime gameTime, MouseState mouse, KeyboardState keyboard, GamePadState ga
(float)gameTime.ElapsedGameTime.totalMillimes
你能帮我弄清楚它为什么不起作用吗?我看到其他人都很好,但我的不行 这就是我的
Player
类(足够大):
更新方法:
public void Update(GameTime gameTime, MouseState mouse, KeyboardState keyboard, GamePadState gamepad, KeyboardState oldKeyboard)
{
m_align = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000;
move(gameTime, mouse, keyboard, gamepad); //On gere le déplacement du joueur
//ACTIONS POSSIBLES
if (keyboard.IsKeyDown(Keys.Space)) //TIR
{
m_weapon[m_activeWeapon].Shoot(ref GameMain.Bullets, m_hitbox, m_direction);
}
else if (keyboard.IsKeyDown(Keys.R) && oldKeyboard.IsKeyUp(Keys.R)) //RECHARGEMENT DE L'ARME ACTIVE
{
m_weapon[m_activeWeapon].reload();
}
if (keyboard.IsKeyUp(Keys.Z) //Si on ne se déplace
&& keyboard.IsKeyUp(Keys.S)
&& keyboard.IsKeyUp(Keys.Q)
&& keyboard.IsKeyUp(Keys.D))
{
this.FrameColumn = 1;
}
if (keyboard.IsKeyDown(Keys.H))
{
m_hp--;
if (m_hp < 0)
{
m_hp = 0;
}
}
属性:
//Attributs
public Vector2 m_position;
public Rectangle m_hitbox;
Direction m_direction;
int m_speed = 3;
float m_align; //Variable d'alignement du temps
string m_name;
int m_hp;
Weapon[] m_weapon;
int m_activeWeapon;
int FrameLine;
int FrameColumn;
int animationSpeed;
SpriteEffects Effect;
int Timer; //animation frames
int SoundTimer; //Son bruit de pas
bool SoundSteps; //Son bruit de pas
默认情况下,更新和绘制方法限制为每秒60次调用。要更改此项,请添加或更改此项:
Game.IsFixedTimeStep = false;
您可以使用TotalSeconds,而不是使用TotalMillistics/1000。但是你的问题没有解决办法。还没能测试(@work)谢谢,我会试试的!
Game.IsFixedTimeStep = false;