0

我正在尝试使用 C# 将“Lives: 3”添加到平台游戏中。

Drawhud()目前游戏以这样的方法绘制分数:

// Draw time remaining. Uses modulo division to cause blinking when the
            // player is running out of time.
            string timeString = "TIME: " + level.TimeRemaining.Minutes.ToString("00") + ":" + level.TimeRemaining.Seconds.ToString("00");
            Color timeColor;
            if (level.TimeRemaining > WarningTime ||
                level.ReachedExit ||
                (int)level.TimeRemaining.TotalSeconds % 2 == 0)
            {
                timeColor = Color.Yellow;
            }
            else
            {
                timeColor = Color.Red;
            }
            DrawShadowedString(hudFont, timeString, hudLocation, timeColor);

            // Draw score
            float timeHeight = hudFont.MeasureString(timeString).Y;
            DrawShadowedString(hudFont, "SCORE: " + level.Score.ToString(), hudLocation + new Vector2(0.0f, timeHeight * 1.2f), Color.Yellow);

我试图画出这样的生活(已经简化了很多代码):

// Players lives
        public const int PlayerLives = 3;

// Draw Player Lives
            float LivesHeight = hudFont.MeasureString(timeHeight).Y;
            DrawShadowedString(hudFont, "Lives: " + Player.PlayerLives.ToString("0"), hudLocation + new Vector2(0.0f, LivesHeight * 1.4f), Color.Yellow);

这不会绘制我在DrawShadowString()方法中创建的字符串。为什么是这样?有没有更简单的方法呢?

这是DrawShadowedString()要求的方法:

private void DrawShadowedString(SpriteFont font, string value, Vector2 position, Color color)
        {
            spriteBatch.DrawString(font, value, position + new Vector2(1.0f, 1.0f), Color.Black);
            spriteBatch.DrawString(font, value, position, color);
        }

谢谢

4

0 回答 0