2

有趣的问题!基本上,我的 UI 有一个计时器,它从 99 开始倒计时。除了在旧时间之上绘制新时间之外,一切正常。(上一次没有清除)GameplayScreens 绘制调用中发生了明显的事情......这很奇怪。

这是我的相关功能:

GameplayScreen.cs(或者我们常用的 Game1)

public override void Update(GameTime gameTime)
{
    m_GameUI.Update(gameTime);
    m_GameCam.lookAt(m_Hero.Position);//feeds the camera's lookAt function the players vector2 position
    m_GameUI.lookAt(m_GameCam.Position); //Look at the camera's position :D
}

public override void Draw(GameTime gameTime)
{

    ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
                                       Color.CornflowerBlue, 0, 0);

    SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

    m_BackgroundManager.Draw(spriteBatch, m_GameCam);      
    //Begin the Spritebatch Drawing
    spriteBatch.Begin(SpriteSortMode.Immediate, null,
        null,
        null,
        null,
        null, m_GameCam.ViewMatrix);

    //Call EntityManager.DrawAllEntities()
    EntityManager.Instance.DrawAllEntities(gameTime, spriteBatch);

    //End the spritebatch drawing
    spriteBatch.End();

    spriteBatch.Begin();
    m_GameUI.Draw(gameTime, spriteBatch);
    m_PlayerUI.Draw(gameTime, spriteBatch);
    spriteBatch.End();
 }

游戏UI.cs

SpriteFont m_Font;
double m_Timer;

public virtual void Update(GameTime gameTime)
{

    m_Timer -= gameTime.ElapsedGameTime.TotalSeconds;

}

public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{

    spriteBatch.Draw(UITexture, Position, Color.White);
    spriteBatch.DrawString(m_Font, "" + (int)m_Timer + "", new Vector2(380, 45), Color.White);
}
4

1 回答 1

0

最终成为一个非常愚蠢的错误,我有一个从 UI 派生的类,它调用 base.draw(),因此更新的时钟和原始值同时显示在屏幕上。基本上是糟糕的代码设计,每个人一开始都是新手,对吧?

感谢您调查它:)

于 2012-12-12T18:41:41.900 回答