thsieh
thsieh

Reputation: 620

XNA WP7 Mango: DrawableGameComponent can be dynamically added to Microsoft.Xna.Framework.Game?

It seems that the class inherited from DrawableGameComponent can be added to Xna.Framework.Game only at Initialize() phase in Game1. Later than that, the component's Draw won't be called. Is there any workaround? The components can be dynamically created at run-time. I need to add the component to be drawn. Thanks!

Upvotes: 1

Views: 215

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32587

Components can be addded to the Game.Components collection whereever you want. If you add a component in the e.g. Update() method, even its Initialize() and LoadContent() methods are called. To draw all components, make sure that the Game.Draw() method contains a call to base.Draw().

If you are experiencing problems only because components are added later, then the problem is probably in the component itself or somewhere else. Make sure that everything exists that the component relies on.

Upvotes: 1

Related Questions