Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am wondering whether the is a mechanism to manually control the call-order of

void Game.LoadContent()

as it is the case with

void Game.Draw(GameTime gt)

by setting

int DrawableGameComponent.DrawOrder

?

  • except the order that results from adding components to the Game.Components container and
  • maybe there exists something similar with Game.Update(GameTime gt) ?

UPDATE

To exemplify my issue consider you have several game components which do depends to each other regarding their instantiation. All are inherited from DrawableGameComponent.

Now suppose that in one of these components you are loading a Model from the games content pipeline and add it to some static container in order to provide access to it for other game components.

public override LoadContent() {

    // ...

    Model m = _contentManager.Load<Model>(@"content/myModel");

    // GameComponents is a static class with an accessible list where game components reside.
    GameComponents.AddCompnent(m);

   // ...

}

Now it's easy to imagine that this components load method has to precede other game components that do want to access the model m in their own load method.

share|improve this question
1  
I think the different Components and their LoadContent() methods should be designed so, that they don't depend on each other or the order you call them. Maybe you can edit your answer with an example where (you think) you need to play around with the load order. –  Marton Nov 2 '12 at 11:46
    
@Marton Well, you are certainly right - avoiding dependencies is always preferable. Nevertheless in my experience the more game components you have in your program the more difficult it gets to decrease or avoid coupling/dependencies. I will add an example to my post ... –  marc wellman Nov 2 '12 at 11:56

2 Answers 2

Now suppose that in one of these components you are loading a Model from the games content pipeline and add it to some static container in order to provide access to it for other game components.

if other components need the model, they should get it throught the content manager...

in case a component need to know what model has other compnent, maybe you need a post initialization method where it succeed

public void Initialize()    {...}
public void PostInitialize() {...}
share|improve this answer

The Game.LoadContent() method will (in the default template) have the line base.LoadContent(); in it. That will call the LoadContent() methods of all your DrawableGameComponents.

If you have content that must be loaded before some other Component tries to access it, then you can simply load it in the Game.LoadContent() method, before calling base.LoadContent();

However, I'm still unsure why you need to access the loaded content from other components before the Update() - Draw() cycle starts.

share|improve this answer
    
This is subtly incorrect. DrawableGameComponent.LoadContent is not called from Game.LoadContent, but from DrawableGameComponent.Initialize (which itself gets called from Game.Initialize during startup; or when the component is added, after startup). –  Andrew Russell Nov 3 '12 at 13:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.