在计时器倒计时图像在c#xna中移动

时间:2013-08-08 16:44:59

标签: c# image if-statement timer xna

这是我的代码:变量:

//Game States
enum gameState
{
    gameLoading,
    mainMenu,
    gameOptions,
    levelSelect,
    gamePlaying,
}
gameState CurrentGameState = gameState.gameLoading;

Update()方法中:

    switch (CurrentGameState)
    {
        case gameState.gameLoading:
    //My gameLoading state logic here
    break;
    //And so on the other states, etc mainMenu, gameOptions, levelSelect, gamePlaying

我的Draw()方法:

    switch (CurrentGameState)
    {
        case gameState.gameLoading:
    //Draw gameLoading state here
    break;
    //And so on the other states, etc mainMenu, gameOptions, levelSelect, gamePlaying

所以我需要像if()这样的东西?和计时器计数30秒,然后调用spriteBatch.Draw()在屏幕上绘制我的图像。

1 个答案:

答案 0 :(得分:1)

你的逻辑似乎很合理。你可以像这样实现它:

您可以创建一个字段:float elapsedTime;

然后在Update()方法中,将经过的时间添加到其中:

elapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

然后在你的Draw()方法中:

if (elapsedTime >= 30.0)
{
    // Draw the image
}