1 Replies - 2176 Views - Last Post: 10 February 2014 - 01:00 PM

#1 BoxxyProgrammer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-November 13

removing/unloading several sprites/drawings XNA

Posted 10 February 2014 - 11:10 AM

okej, I have almost done a whole XNA game and now i have the problem with unloading/removing some sprites i have drawn in my draw method. these sprites are drawn in other classes(as in character, map and menu classes)

I have the problem that when i go in to the Playing mode and then go to the menu the menu cannot be seen because it is drawn before the Map-class.

do you have any tips how to fix this or do you know any links where i can find a strate answer.

thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: removing/unloading several sprites/drawings XNA

#2 BBeck   User is offline

  • Here to help.
  • member icon

Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: removing/unloading several sprites/drawings XNA

Posted 10 February 2014 - 01:00 PM

In general, things are drawn in the order that they are drawn. So, whatever you draw last is going to be on top and cover up whatever you drew before.

There are various methods to overcome this that most all revolve around a Z axis.

In the sprite method, there is a depth parameter. SpriteBatch.Draw() has a LayerDepth parameter that's for determining what gets drawn on top.

Of course, you may be doing something that messes this up. I don't know if multiple sprite batches might override this largely because I work so little with sprites. But I could see where it might.

So, you either have to draw it in the order you want it to appear, or you have to come up with a scheme to do sort of a deferred rendering and draw them in Z order.

GameComponents have order, if you are using GameComponents you can set the order so that a menu game component would draw last, for example.

Without GameComponents, you may just have to get your draw calls in order, if there's no way to control the Z order.

(Incidentally, you may not know about the Z axis if you work strictly in 2D. That's a 3D idea, but it's used a lot even in 2D. Really, since DX10 and OpenGL 4.0, even 2D stuff actually gets drawn in 3D and so there is a "depth", or Z, axis. In 3D there is a depth buffer that keeps track of Z order and can be a bit of a trick when dealing with transparency and whatnot. The DepthBuffer is what keeps track of depth in 3D drawing and "generally" works automatically in the background until you do something wrong, like unknowingly turn it off because you wanted something in the back, like a menu, to show up at the front. The DepthLayer setting in the Draw() method is basically doing a very shallow Z axis that generally only has a depth between 0 and 1. But that's usually all you need to specify the depth of sprites.)

This post has been edited by BBeck: 10 February 2014 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1