Should the update method call the draw method?

I have a class named “MarblesRemainingInBag” with an Update and Draw method in it. If I call the update method for this class from my main class shouldn’t the draw method in the class be called after calling the update method?

My main class is : “public class Game1 : Microsoft.Xna.Framework.Game”
and in the update method I call the Update method of my “MarblesRemainingInBag” class
ex:
marbsRemaining.Update(graphics.GraphicsDevice);

My MarblesRemainingClass is shown below
public class MarblesRemainingInBag
{
SpriteFont Scorefont;
public Vector2 marbleCountLocation;
public Vector2 Origin;
public int totalMarbles;
public MarblesRemainingInBag(SpriteFont font, int CountLocationX, int CountLocationY)
{
Scorefont = font;
Origin.X = 0;
Origin.Y = 0;
marbleCountLocation.X = CountLocationX;
marbleCountLocation.Y = CountLocationY;
}

    public void countUpdate(int marbRemaining)
    {
        totalMarbles = marbRemaining;
    }

    public void Update(GraphicsDevice graphics)
    {

    }

    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.DrawString(Scorefont, "Total :" + totalMarbles, marble, Color.WhiteSmoke, .5f, Origin, 1.0f, SpriteEffects.None, 0.5f);
    }

  

}

Your objects can contain individual calls to Draw(), learn to build an engine and you can see the magic happen.

:dizzy:

1 Like

To answer the titular question, no, you shouldn’t call any Draw methods in any Update methods. Instead, just like you call the Update method of your MarblesRemainingInBag class in the Update method of Game1, you should call the Draw method of MarblesRemainingInBag in the Draw method of Game1. Keep your Update calls in your Update methods, and your Draw calls in your Draw methods.

Hope that helps!

2 Likes

Yeah, that!

2 Likes

Thanks guys !

2 Likes