Domanda

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);
}
È stato utile?

Soluzione

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 :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top