定时器绘图在自身之上,不清除

时间:2012-12-09 19:50:32

标签: c# xna spritefont

有趣的问题!基本上我的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();
 }

GameUI.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);
}

1 个答案:

答案 0 :(得分:0)

结果是一个非常愚蠢的错误,我有一个派生自UI的类,它正在调用base.draw(),因此更新的时钟和原始值都会立即显示在屏幕上。基本上糟糕的代码设计,当他们刚开始时,每个人都是新手吗?

感谢您查看:)