As you know, the predefined Game1 class in a Windows Game, already has separate Update and Draw methods. I know these are used when the Game is running, in the way that it will Update 60 times a second, and only draw if it has the time. Something like that (you know what I mean).
Now, as I would imagine many of you would do, I have a GameObject class, with an Update and Draw method, and then all my 'gameObjects' inherit GameObject. The obvious way to Update your Objects in my opinion is using a loop like so :
Update method...
foreach (GameObject o in gameObjects)
{
o.Update(gameTime);
}
Draw method...
foreach (GameObject o in gameObjects)
{
o.Draw(spriteBatch);
}
I tend not to like using the Game1 class, I think because I don't really know what it does. I'm one of those people who like to know exactly what something is doing (if you know what I mean). So what I do is create another class, something like Manager.
Then I create my own Initialize and Updater methods in that.
That way, I only have 2 lines of code in the Game1 class.
Manager.Intialize(parametres); In the Initialize method of Game1
Mangaer.Updater(parameters); In the Update method of Game1.
It's purely choice that I have it in 2 lines, and not 4, because I could be uisng Initialize, LoadContent, Update and Draw.
Now what this means, it that I only have 1 foreach loop for Updating and Drawing instead of 2. Like so.
public void Updater(GameTime gameTime, SpriteBatch spriteBatch)
{
foreach (GameObject o in gameObjects)
{
o.Update(gameTime);
o.Draw(spriteBatch);
}
}
So that is the benefits. The Cons are I suppose that I will always be running through the Drawing stuff, whereas the framework is designed to have 2 seperate methods.
Is this a good Idea?
Or should I revert back to using 2 methods for Update and Draw?
Another benefit I thought of is that, I actually have all my objects draw and updated in a specific order. So an example is, anything under the pause screen is Update and Draw before the PauseScreen is actually Update itselft. If that made sense. Like this :
Object1.Update
Object1.Draw
Object2.Update
Object3.Update
Object2.Draw
Object3.Draw
And in some cases, it's important the order they're in.
Thanks in advance,
Daniel,
Wow. I just reread that, and could have just said, is using 2 foreach loops going to be less efficient that using 1? I must be getting that from BBeck
This post has been edited by DanielLeone: 09 June 2012 - 12:08 AM

New Topic/Question
Reply



MultiQuote









|