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

本文关键字:c#xna 移动 图像 倒计时 计时器 | 更新日期: 2023-09-27 18:26:50

这是我的代码:变量:

//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()在屏幕上绘制我的图像。

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

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

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

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

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

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

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