2

Interesting problem! Basically I have a timer for my UI that counts down from 99. Everything works fine save for the fact its drawing the new time on top of the old time. (The previous time is not clearing) There is a clear happening within the GameplayScreens draw call though... its just weird.

Here are my related functions:

GameplayScreen.cs (or our usual 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);
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Is there a reason you're not using `GraphicsDevice.Clear(Color)`? Also, what is `ScreenManager`? – neeKo Dec 10 '12 at 14:16
  • My game has different menu states controlled by the screenmanager where the GraphicsDevice is defined, one of which is *GameplayScreen* where the game logic actually kicks in. I am performing my clear in the GameplayScreen's draw at the top "ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.CornflowerBlue, 0, 0);" – EmericanFlow Dec 10 '12 at 14:29
  • Does it make a difference if you just use Clear(Color.CornflowerBlue)? I've never seen that overload used, unless your parameters are used for a reason (they look like defaults), it's simpler just to use the single Color parameter overload. – A-Type Dec 10 '12 at 18:42
  • Yah I've given that a shot as well, surprisingly the game itself was not effected by the overload which has me questioning my overall programming logic haha. Thanks for giving it a shot :), I think I am on to something though if it works I will post it up! – EmericanFlow Dec 10 '12 at 19:36

1 Answers1

0

Ended up being a really silly mistake, I had a class deriving from the UI that was calling base.draw() so both the updated clock and the original value were being displayed on the screen at once. Basically poor code design, everyone is a newbie when they start out right?

Thanks for looking into it :)