我正在尝试使用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);
}
由于