因此,我在Microsoft Visual Studios中遇到问题,我也在使用Monogame,得分绘制在其自身上,即0与5混合,依此类推。
想知道是否有人可以解决这个问题。
我的代码在下面列出。

    protected override void Draw(GameTime gameTime)
    {

        // TODO: Add your drawing code here

        timer += gameTime.ElapsedGameTime.TotalMilliseconds; // Increment the timer by the elapsed game time.

        if (timer >= 10000) // Check to see if ten seconds has passed.
        {
            score += 5; // Increment the score by 5.
            timer -= 10000; // Reset the timer.
        }

        spriteBatch.Begin();

        spriteBatch.DrawString(font, "Score: " + score, new Vector2(50, 70), Color.DarkRed);
        spriteBatch.DrawString(font, "Time Elapsed", new Vector2(50, 50), Color.GhostWhite);

        spriteBatch.End();

        base.Draw(gameTime);
    }

最佳答案

您可以清除绘制之间的屏幕,将这一行放在开头;

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);   // Clear screen
    ....

09-12 06:26