Game Development Community

TorqueX,sprites rendering order in the same layer

by Ruisen Luo · in Torque Developer Network · 02/16/2011 (6:37 am) · 0 replies

Hey, all
I'm developing a new game with TorqueX1.5 which has lots of sprites in the same layer(32 fixed layers are not enough for me), but what makes me confused is the rendering order of these sprites in the same layers. It seems that they never have a fixed relative order between them at rendering time and often alternately covering each other. I read the document and created an IComparer<ISceneContainerObject> interface like this:
Game : TorqueGame, IComparer<ISceneContainerObject>
{
...
public int Compare(ISceneContainerObject x, ISceneContainerObject y)
{
int ret;

int xHashcode = RuntimeHelpers.GetHashCode(x);
int yHashcode = RuntimeHelpers.GetHashCode(y);

if (xHashcode > yHashcode)
{
ret = 1;
}
else if (xHashcode < yHashcode)
{
ret = -1;
}
else
{
ret = 1;
}
return ret;
}
...
}
and added it into the scenegraph:
sceneGraph.LayerSortDictionary.Add(0, this);

It didn't work until i eanbled the depth buffer:
sceneGraph.UseDepthBuffer = true;

But a new problem occurred, the alpha blending was broken! All my materials with alpha channel can not be presented in the right way! I had paid a lot of time in this stuff and still can't find a way both solve the in-layer rendering order and alpha blending problems.
Need some help!

Thanks

About the author

Recent Threads