精灵随机停止绘制XNA 4.0

时间:2016-08-09 08:54:49

标签: c# sprite xna-4.0

我正在XNA制作一个简单的2人射击游戏。

当我按住空格键的同时射击时,射弹的精灵被拉出,但是当我松开空格键并再次射击时,第一个精灵根本就没有被绘制。

但是它仍然在游戏中并且正常运行,代码是否存在问题或者是否有任何解决方案?

protected override void Draw(GameTime gameTime)
{
    //Loading and Drawing the background through XNA spriteBatch

    spriteBatch.Begin(0, BlendState.AlphaBlend);
    spriteBatch.Draw(backgroundTexture, GraphicsDevice.Viewport.Bounds, Color.White);
    //Drawing the spaceship on the screen
    spriteBatch.Draw(spaceship.sprite, spaceship.position, null, Color.White);
    //Drawing the alienship
    spriteBatch.Draw(alienship.sprite2, alienship.position2, null, Color.White);
    spriteBatch.End();
    //Drawing the projectile

    spriteBatch.Begin(0, BlendState.AlphaBlend);
    if (projectile.alive == true)
    {
        spriteBatch.Draw(projectile.sprite, projectile.position, Color.White);
    }

    //Drawing the 3rd Projectile
    if(projectile3.alive == true)
    {
        spriteBatch.Draw(projectile3.sprite, projectile3.position, Color.Red);
    }

    //Drawing the 4th Projectile
    if (projectile4.alive == true)
    {
        spriteBatch.Draw(projectile4.sprite, projectile4.position, Color.Green);
    }

    //Drawing the Special Projectile
    if (projectile2.alive)
    {
        spriteBatch.Draw(projectile2.sprite, projectile2.position, Color.White);
    }

    spriteBatch.End();
    // TODO: Add your drawing code here

    base.Draw(gameTime);
}

1 个答案:

答案 0 :(得分:0)

这不是一个真正的答案,但我没有足够的代表发表评论。

我不认为这是XNA或您发布的任何代码的问题。相反,问题最有可能出现在代码的另一部分。你说精灵没有绘画,并且根据你的例子中的if语句,我首先要检查所有的射弹是否还活着。

为此,在每个if语句处插入断点,右键单击它们,单击" condition ..."然后输入projectile.isalive == false,看看弹丸是否已经死亡。那将是一个起点。

相关问题