2012-01-17 63 views
0

對,我得到的遊戲是2D賽車遊戲。我已經在遊戲中實現了終點線圖像等等。我把它作爲一個單獨的精靈表。以下是我試圖以這種方式改變的代碼,即'如果car1blue與finishLine1相交,則結束遊戲。'但我似乎無法做到。這是我試圖改變的代碼;如何在XNA 4.0中添加結束屏幕?

if (IntersectPixels(destinationBlueRect, finishLine1TextureData, finishLine1Rectangle, finishLine1TextureData)) 
{ 
    blueHit = true;     
} 

它甚至會更好,如果你能告訴我如何添加一個結束比賽的消息說,「球員1勝」(當車穿越finishline1)和結束比賽大約三秒鐘後呢?

歡迎任何幫助(我是新手)。謝謝!

回答

1

您可能要實現這個Game State Management系統,爲您的延遲:

float delayTime = 3000;// Time to delay in milliseconds 
float delayBuffer = 0;// This will count how much time has passed 

// In your Update method 
if (blueHit) {// You should change this to whatever way you find if someone has won the game 
    if (delayBuffer < delayTime) { 
     delayBuffer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; 
    } else { 
     // Show the last screen 
    } 
}