gui.Draw() doesnt work for me

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


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

and added 
to the Update method and 
to the draw method.

but there is no gui.

any help?

Feb 2, 2012 at 6:14 PM



in Game.Initialize();

Feb 2, 2012 at 6:48 PM

working now. Thanks!

Feb 3, 2012 at 4: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 5: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 8: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.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






//over gui (custom mouse  cursor for example)




Feb 21, 2012 at 9: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 :)