Depth of GameComponents?

Hey, I've been trying out some features of XNA and I noticed that one really necessary feature is missing... there is no way to set the order in which game components are drawn in the existing framework. I would really appreciate a Depth or ZOrder property of the GameComponent class and a Sort() method for GameComponentCollection. Maybe there is another way to do this, but I would find it a lot easier than using the Insert() method, since developers may want to change the order after adding the component. This is probably a pretty crude explanation as I haven't given that much thought to it, but it still seems that some sort of solution to this would be very useful. Please tell me what you think or plan to do - thanks.
[730 byte] By [AlexReg] at [2007-12-25]
# 1
Do you have a situation where you'd need this?
JimPerry at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2
Thanks for the suggestion, we'll look into it.
MitchWalker-MSFT at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3
Here's an example I ran into with this problem

I have a game with two components terrain and fpscounter. Without ordering, fpscounter may draw first then be overwritten by terrain. or If you use zbuffering fps appears but if your font has transparency to smooth the edges it looks all ugly, so ordering is important.

I had to comment out DrawCommponents and call each components.Draw manually in the order i wanted. Some simple integer zorder property on the components could work though.

Sorting could occur only when opponents are added or removed and the game could subscribe to a ZorderChanged event for each of it's child components?

T-MeK at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4

Similar suggestions ahve been made in connect

See (you must be logged into connect before the links will work)

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=195718&SiteID=226

and more like it

https://connect.microsoft.com/feedback/SearchResults.aspx?SearchQuery=gamecomponent+&SiteID=226

Please search connect to see if your suggestions have already been made

TheZMan at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 5
I kind of lost track of this thread. :O But it's very good to hear you're looking into it.
AlexReg at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 6
T-MeK wrote:
[...] I

had to comment out DrawCommponents and call each components.Draw

manually in the order i wanted. Some simple integer zorder property on

the components could work though. [...]

Is there a reason you commented out the DrawComponents call instead of simply overriding it altogether?

MichaelSchuld at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 7

MY TEST

the Update order cannot be controlled but orde of drawing can be controlled is very easy !!

private GrapM _grapm;
public GrapM CommonGraphics
{
get { return _grapm; }
set { _grapm = value; }
}

private SpriteBlendMode _blendedmode;
public SpriteBlendMode Alpha
{
set { _blendedmode = value; }
}

private float _Order;
public float Order
{
get { return _Order; }
set { _Order = value; }
}

private int _X;
public int X
{
get { return _X; }
set { _X = value; }
}

private int _Y;
public int Y
{
get { return _Y; }
set { _Y = value; }

....Texture information...bla...bla


load resoruces ..and draw....... use five SpriteBhach.Draw overload of the method

_grapm.spritebatch.Draw(Texture, new Vector2(_X, _Y), null, Color.White, 0f, new Vector2(0, 0), 0f, SpriteEffects.None,_Order);

GrapM and a component that is in charge of the Device and the Spritebach..

public partial class GrapM : Microsoft.Xna.Framework.GameComponent

{
public SpriteBatch spritebatch;
public GraphicsDevice Device;

public
GrapM(){}

public override void Start()
{
IGraphicsDeviceService gfxService = Game.GameServices.GetService<IGraphicsDeviceService>();
Device = gfxService.GraphicsDevice;
//Iniciamos el SpriteBach
spritebatch = new SpriteBatch(Device);
}
}

Conclusions:

  1. The project to create "components Draw Sprites" is lost of time!!!!!
  2. To control the Draw order is very easy but impossible is the Update

hanagomi at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...