我对 XNA 游戏工作室有疑问。我不知道为什么这段代码不起作用,如何产生导弹?我在这里尝试做的是在每次按下空间时产生一枚导弹。
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
keys = Keyboard.GetState();
if (keys.IsKeyDown(Keys.Up))
{
spaceshipRectangle.Y -= 5;
}
if (keys.IsKeyDown(Keys.Down))
{
spaceshipRectangle.Y += 5;
}
if(keys.IsKeyDown(Keys.Space))
{
missileShot = true;
missile = Content.Load<Texture2D>("Missile");
missileRectangle = new Rectangle(spaceshipRectangle.X, spaceshipRectangle.Y, 30, 40);
spriteBatch.Begin();
spriteBatch.Draw(missile, missileRectangle, Color.Green);
spriteBatch.End();
}
if (missileShot = true)
{
missileRectangle.X += 5;
}
// TODO: Add your update logic here
enemyRectangle.X -= 5;
base.Update(gameTime);
}
谢谢你。