2016-08-09 83 views
1

我正在XNA製作一個簡單的2人艦船射擊遊戲。Sprites隨機停止繪製XNA 4.0

當我火的時候按住空格鍵的彈精靈繪製,但是當我放開空格鍵和拍攝又是第一個精靈是不是在所有的繪製。

但它仍然在遊戲和功能的意圖,有代碼的問題或有任何解決方案嗎?

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); 
} 

回答

0

這不是一個真正的答案,但我沒有足夠的代表評論。

我不認爲這是XNA或任何您發佈的代碼的問題。問題很可能發生在代碼的另一部分。你說這個精靈並沒有繪製,並且根據你的例子中的if語句,我會開始檢查所有的彈丸是否還活着。

爲此,在每個if語句中插入斷點,右鍵單擊它們,單擊「條件...」,然後輸入projectile.isalive == false,並查看拋物線是否應該不是死的。那將是一個起點。