简体   繁体   中英

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!

Components can be addded to the Game.Components collection whereever you want. If you add a component in the eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM