GameComponents controlling GameComponents

Most XNA game examples I have seen so far load all the game components right away at the beginning of the game no matter what. I looking to setup a GameComponent (GameWorld) which the user will control to load which will subsequently load several other game entities which are inherited from the DrawableGameComponent as well, but they all controlled by the GameWorld as far as enabled/visible. This appears to work fine so far, I'm just curious though if there is anything wrong with this finite number of game entities all having there own SpriteBatch property because of this. Performance issue when GraphicsDevice is recreated Or even if this is a workable practice In other examples, I've seen certain drawable game entities custom created while just passing a SpriteBatch to their draw method from whatever GameComponent/Game controls them.

Any thoughts


Answer this question

GameComponents controlling GameComponents

  • kirank_gh

    I figured someone should be a little more explicit about a possible downfall ;)

  • happymozart

    Jim, Just making sure I understand you here.

    Are you saying query the SpriteBatch via the services route

    Or are you saying query the Graphics Device The main GameWorld component is a Drawable one as are the GameComponents its starts, thus they appear to handle the GraphicsDevice themselves or is this not the case either

    Thanks,
    Evan



  • Mark Benningfield

    Yes I could probably do that... thanks for the tip.

  • drndrw

    Rather than do that, I'd recommend making it a service and have components query the game for the service. You can find an old article on the subject here.

  • MarissaM

    Well as long as the SpriteBatch properties are going to be the same for all the components, I would recommend creating a single SpriteBatch at the beginning and passing it to all the constructors for the components.

  • kageg

    Until, of course, a device reset happens....

  • Blackuke

    Which is why I suggested the service route.

  • GameComponents controlling GameComponents