gui.Draw() doesnt work for me

Feb 2, 2012 at 7:00 PM
Edited Feb 2, 2012 at 7:02 PM

hello,

i recently started working with xna and the nuclex framwork, so im still pretty noobish.

so i get right to the point: i tried drawing the gui with its Draw() method in the UserInterface demo project. but all i see is the gray background.

i just commented the line

Components.Add(this.gui);
and added 
this.gui.Update(gameTime)
to the Update method and 
this.gui.Draw(gameTime)
to the draw method.

but there is no gui.

any help?

Feb 2, 2012 at 7:14 PM

add

this.gui.Initialize();

in Game.Initialize();

Feb 2, 2012 at 7:48 PM

working now. Thanks!

Feb 3, 2012 at 5:02 PM

sorry to bother u again with my rather noobish questions.

so im using the gui along with other 2d components. the problem is it doesnt matter at wich point i call the draw method of each the components and the gui. the gui is always behind everything. i already tried adding everything to the Game.Components and setting GuiManager.DrawOrder = 1000. its still the same.

any help please?

Feb 4, 2012 at 6:35 PM

got is fixed by calling spriteBatch.End() and spriteBatch.Begin(), before calling draw() on the guiManager. dont know why it works, but i does :)

Feb 6, 2012 at 9:13 AM

Sorry for my Engrish :)

NuclexGUI uses it's own SpriteBatch. All calls of SpriteBatch.DrawSomething put arguments in queue and actualy draw at moment, where you call SpriteBatch.End So, if you dont Finish game SpriteBatch before call gui.Draw() it looks like:

 

game.SpriteBatch.Begin() - begin draw queue for game

------- draw code - actualy not draw,

gui.Draw()

   gui.SpriteBatch.Begin() - begin queue for gui

   -----

   gui.SpriteBatch.End() - Draw gui at BackBuffer

game.SpriteBatch.End() - Draw game over Gui.

 

 

if you need draw somesing over gui, you can call SpriteBatch.Begin/End several times for example

//under gui

game.SpriteBatch.Begin()

---

game.SpriteBatch.End()

//gui

gui.Draw()

//over gui (custom mouse  cursor for example)

game.SpriteBatch.Begin()

---

game.SpriteBatch.End()

Coordinator
Feb 21, 2012 at 10:15 AM

Aah, it's always hard to find out what's going on in these cases without looking at the code.

If you're still wondering why it works:

The SpriteBatch "batches" things you draw (which means instead of telling the graphics card a hundred times "draw a sprite at x, y", it collects your drawing commands and when you ultimately call SpriteBatch.End(), it tells the graphics card "draw these 100 sprites at these positions").

So without calling SpriteBatch.End(), your SpriteBatch just keeps collecting things to draw. Then the GUI draws, and finally, when SpriteBatch.End() is called, all those collected things are actually drawn - on top of the GUI even though in code, the DrawRectangle() etc. calls were before the GUI.

Glad you god it solved yourself :)