2012-12-09 46 views
2

有趣的问题!基本上我有一个计时器,用于我的用户界面,从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); 
} 
+0

有没有你不使用'GraphicsDevice.Clear(彩色)'理由吗?另外,ScreenManager是什么? – neeKo

+0

我的游戏有不同的菜单状态,由ScreenManager控制,其中GraphicsDevice被定义,其中一个是* GameplayScreen *,其中游戏逻辑实际踢入。我在顶部的GameplayScreen绘图中执行我的清除“ScreenManager.GraphicsDevice.Clear (ClearOptions.Target, Color.CornflowerBlue,0,0);“ – EmericanFlow

+0

如果您只使用Clear(Color.CornflowerBlue),它会有所作为吗?我从来没有见过使用重载,除非你的参数被用于某种原因(它们看起来像默认值),使用单一颜色参数重载更简单。 –

回答

0

结束了一个非常愚蠢的错误,我有一个派生自UI的类,它调用base.draw(),所以更新的c锁定和原始值一次显示在屏幕上。基本上糟糕的代码设计,每个人在刚开始的时候都是新手?

感谢您寻找到它:)