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

GameStateManagement and DrawableGameComponents

Last post 5/30/2009 6:09 AM by Craig Martin. 6 replies.
  • 5/29/2009 11:09 AM

    GameStateManagement and DrawableGameComponents

    Hey all,

    I've been messing around for a few weeks now, and I created a simple little game by creating my objects as extensions of the DrawableGameComponent class.

    Now it's time to add the menu system, and I've been playing around with the GameStateManagement sample, and I understand it for the most part, but what I can't figure out is how to add my DrawableGameComponents to the GamePlay screen?

    I tried to create instances of my camera (from the ChaseCamera sample) and my Character object to the list of components like so:

    ScreenManager.Game.Components.Add(new Character());

    but they won't show up (because the screen seems to be in the way?)

    I REALLY don't want to have to rewrite my characters as non drawable game components and handle them in the GamePlayScreen.

    Someone please tell me how to add DrawableGameComponents to the GamePlay screen?

    I tried looking into the Pikture demo, but it's completely confusing, one screen calls another screen which calls another screen which calls the draw method to the board, which calls the draw method to the chip, and on and on and I can't grasp how they have access to all the GraphicsDevice variables and such that they need throughout the process.

    [EDIT] I just wanted to add on to this. I tried making one of my objects a non-DrawableGameComponent and then manually called the Update() and Draw() methods from within my GameScreen class, but all I get is a black screen. There are no other Drawing functions inside my GamePlayScreen.Draw() method aside from the call to Draw my object.
    [/EDIT]

    Thanks,
    Tim
  • 5/29/2009 1:21 PM In reply to

    Re: GameStateManagement and DrawableGameComponents

    I have used GSM and NSM extensively.

    There's no reason why ScreenManager.Game.Components.Add(YourComponent) won't work. You say that the screen seems to be in the way? Do you mean that the screen is being drawn over your DrawableGameComponents? If so, then you need to change your component's DrawOrder so it is above ScreenManager.
    "Software is never finished, it is in varying states of 'less broken'" because "If it ain't broke, it doesn't have enough features yet"

    In Playtest: Avatar Land | The MANLY Game for MANLY Men

    The signature that was too big for the 512 char limit
  • 5/29/2009 2:34 PM In reply to

    Re: GameStateManagement and DrawableGameComponents

    I say it looks like the screen is in the way because the default GamePlayScreen (for the NetworkStateManagementExample) shows the number of connected users. Eventually I removed all code from the GamePlayScreen's Draw method, and was left with just an empty screen. It just doesn't seem as though anything is being drawn. I created my ChaseCamera and my objects but they did not show on screen at all.

    I'll try setting the DrawOrder to something considerably higher and then get back to you.

    Thanks,
    Tim
  • 5/29/2009 4:23 PM In reply to

    Re: GameStateManagement and DrawableGameComponents

    madgamer:
    I say it looks like the screen is in the way because the default GamePlayScreen (for the NetworkStateManagementExample) shows the number of connected users. Eventually I removed all code from the GamePlayScreen's Draw method, and was left with just an empty screen. It just doesn't seem as though anything is being drawn. I created my ChaseCamera and my objects but they did not show on screen at all.

    I'll try setting the DrawOrder to something considerably higher and then get back to you.

    Thanks,
    Tim


    It maybe because you are creating your DrawableGameComponents in the game class, and then the ScreenManager is added to the game.Components after that, so the ScreenManager is being drawn last, overwriting your other objects.

    You can change the DrawOrder above, or what I think is better is to create the DrawableGameComponents in your GameplayScreen class, then they will be added to the game.Components list after the ScreenManager and draw over the top of the current screen without having to play with DrawOrder.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 5/29/2009 5:04 PM In reply to

    Re: GameStateManagement and DrawableGameComponents

    Hey guys,

    So far, no luck. I set the DrawOrder of my objects all the way up to 10000 during the testing.

    I am creating the instances of my DrawableGameComponents from within the GameScreen LoadContent() method.


    I have absolutely nothing in the Draw() method of GameplayScreen.

    I was wondering if the problem is with the camera... I tried passing the camera (also a DrawableGameComponent from the ChaseCamera demo - and also set all the way to 10000 DrawOrder). So I tried passing the camera as a 'ref' because I couldn't figure out how to get it as a Service.

    [EDIT]
    The worst part is that I can't even really debug it. I'm setting up breakpoints and everything is getting called as expected, it's just not being drawn on the screen.
    [/EDIT]

    [EDIT]
    I figured out how to register the camera as a Service thanks to this thread: http://forums.xna.com/forums/p/29541/166550.aspx - unfortunately I still have the same result. A plain black screen.

    I should reiterate that when run on it's own (without the gamestatemangement) this code works flawlessly.
    [/EDIT]

    I have posted my latest GameplayScreen code at pastebin: http://pastebin.com/m1bb6f407
    I don't think it should be necessary to post the Cycle or ChaseCamera code, as the ChaseCamera is pretty much stock from the example, and my object works just fine on it's own when created and added from the Game class (without the gamestate code).

    Completely stuck here.
    Thanks,
    Tim

  • 5/30/2009 6:06 AM In reply to

    Re: GameStateManagement and DrawableGameComponents

    omg. I am so ridiculous. I forgot that the model I was using was actually quite tiny, and I had to scale it up a LOT. So it was drawing all the time... doh!

    Now, the problem remains that the model isn't drawing "properly" It's like see-through... very weird. It is drawing, I can see the outlines of it. The model worked fine when I was creating it from the Game.cs class.


  • 5/30/2009 6:09 AM In reply to

    Re: GameStateManagement and DrawableGameComponents

    Well done, it's nice when you fix it youself eh?

    Put these lines in before you draw your model.

        GraphicsDevice.RenderState.DepthBufferEnable = true;
    GraphicsDevice.RenderState.AlphaBlendEnable = false;
    GraphicsDevice.RenderState.AlphaTestEnable = false;

    See here for full explanation.
    Game hobbyist hell-bent on coding a diabolical Matrix
Page 1 of 1 (7 items) Previous Next