XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Questions about game omponents

Last post 03/11/2009 7:12 AM by Catalin Zima. 4 replies.
  • 03/11/2009 6:25 AM

    Questions about game omponents

    Hello,  everyone I have a quick question about game components. I am writing my object manager and here is what I am thinking,  If I make my object manager contain a list of a base class objects that derive from the GameComponent class of XNA, this will force XNA to update them itself correct? 

    If this is the case then I would be updating objects twice if I ran another update inside the Object Manager then when I called the individual objects update specifically am I correct? 

    And if this is the case the base class should just be a class with simply a position and rotation that dose not derive from anything. 

    Any feedback is greatly appreciated,  and thanks everyone?  
  • 03/11/2009 6:48 AM In reply to

    Re: Questions about game omponents

    Answer
    Reply Quote

    The XNA Game class only updates GameComponents that have been added to it's Components collection.

    So if you have an ObjectManager with a list of GameComponents, and call the Update method on those GameComponents manually, that is fine, as long as they have not also been added to the Game class Components collection.

    But creating an ObjectManager for maintaining a List of GameComponents would be a bad design because the GameComponents have some protected methods (like I think LoadContent), so your ObjectManager class could not access these without redirection.

    So if you want to have an ObjectManager class, it would be better if you didn't use GameComponents, and just roll your own. If you roll your own, you could have them inherit from the same interfaces that GameComponents do, if you want to maintain some sort of commonality.

    Game hobbyist hell-bent on coding a diabolical Matrix
  • 03/11/2009 7:02 AM In reply to

    Re: Questions about game omponents

    Awesome Craig,  I appreciate the response.  After I Get done writing my object manager I will post it here to see if you guys see some stupid mistakes or have suggestions.  I really appreciate the feed back.  As far as the commonality goes I could put standard functions such as update,, draw and load content in the class itself.  One last question for you though if you dont mind.  If I stick my game objects in between a sprite batch begin and sprite bach end I would not need to call the sprite batch begin and end inside of each object correct?
  • 03/11/2009 7:05 AM In reply to

    Re: Questions about game omponents

    Correct.
  • 03/11/2009 7:12 AM In reply to

    Re: Questions about game omponents

    Angel Oblivion:
    If I stick my game objects in between a sprite batch begin and sprite bach end I would not need to call the sprite batch begin and end inside of each object correct?

    Not only do you not need to call spritebatch begin/end for each object, but it would be a very bad thing from a performance point of view to do that.
    For spriteBatch it is good to have as many draw calls as possible between a Begin and an End.
Page 1 of 1 (5 items) Previous Next