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 have a small 2D game I'm working on in XNA. So far, I have a player-controlled ship that operates on vector thrust and is terribly fun to spin around in circles. I've implemented this as a DrawableGameComponent and registered it with the game using game.Components.Add(this) in the Ship object constructor.

How can I implement features like pausing and a menu system with my current implementation? Is it possible to set certain GameComponents to not update?

Is this something for which I should even be using a DrawableGameComponent? If not, what are more appropriate uses for this?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can set the Enabled property on the game component to false. The game won't update it. You can also set the Visible property to false and the game won't tell it to draw. It can get kind of messy when you have a lot of game components. You might want to consider using some game state management and sub dividing your game components into separate states.

That way game components that are part of the game play can be told to not draw/update when the game state is told not to update or draw, etc.

This is a pretty good example of game state management: Game State Management Sample

So then you could have your PlayScreen (the state with the game play in it) and have a the PauseScreen come on top of it. The PlayScreen wouldn't be updated, but it would still draw. (or something of that nature)

share|improve this answer
2  
So the Enabled and Visible properties control whether or not the Update() and Draw() methods, respectively, will be called? If Visible is false, will ANY code in the Draw() method execute or is it simply not called? Do they affect anything else? –  Bill Feb 5 '11 at 18:24
2  
They won't be called, and they only affect Update (Enabled) and Draw (Visible). –  r2d2rigo Feb 6 '11 at 1:20
    
Then this is exactly the functionality I was hoping for. Thanks. –  Bill Feb 6 '11 at 5:49

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.