Drawing order
by Vern Jensen · in Torque Game Builder · 02/18/2008 (11:54 am) · 6 replies
Is there any way to move a given t2dSceneObject to the front or back of its layer?
I know you can change layers, and it seems when you do so, the object is put at the front of the new layer. Any way to move an object around *within* its current layer? (A simple "move to front" or "move to back" call.) Or any way to fake this behavior with some creative thinking?
I know you can change layers, and it seems when you do so, the object is put at the front of the new layer. Any way to move an object around *within* its current layer? (A simple "move to front" or "move to back" call.) Or any way to fake this behavior with some creative thinking?
#2
If I call:
mySceneGraph.setLayerDrawOrder( %mySprite, BACKWARD);
will that cause this sprite to be "moved" to the back of its layer? Or does it set some flag that causes it to always be rendered in a certain order?
I'm basically wanting to "move" a sprite to either the front or the back of a given layer, but if a *different* sprite is later moved to the front or back, then *that* sprite should now be the new head or tail. And I'm not sure if setLayerDrawOrder would do this, but then again I don't understand exactly how the function works, since your post is the most I know about it. (The documentation I have is from 1.5.1, which is minimal.)
02/18/2008 (12:51 pm)
Could you elaborate a little bit on how this command works? If I call:
mySceneGraph.setLayerDrawOrder( %mySprite, BACKWARD);
will that cause this sprite to be "moved" to the back of its layer? Or does it set some flag that causes it to always be rendered in a certain order?
I'm basically wanting to "move" a sprite to either the front or the back of a given layer, but if a *different* sprite is later moved to the front or back, then *that* sprite should now be the new head or tail. And I'm not sure if setLayerDrawOrder would do this, but then again I don't understand exactly how the function works, since your post is the most I know about it. (The documentation I have is from 1.5.1, which is minimal.)
#3
02/18/2008 (1:03 pm)
I believe that BACKWARD will move it by one in the order, and that BACK will move it to the front of the list as you want. Probably best to try some experiments.
#4
02/25/2008 (1:04 pm)
With some quick testing just now, it seems that FRONT and BACK have the exact behavior as you suggested they might (move to front/back of the list). Awesome! Thanks so much for the help, Dan!
#5
02/27/2008 (12:27 am)
You can also do that in the editor using the back/forward arrows.
#6
What happens is that the order they were summoned to the stage is their order *within* the layer. If I drag one t2dStaticSprite that is more in front of another, the collision works, everything is fine (the t2dStaticSprite collides and drags all the objects under it along, sliding them, as if you were pushing little squares against each other off a table; However, reverse that ( drag a t2dStaticSprite that is behind another, over it ) and the collision is there, but the t2dStaticSprite fails to follow the cursor when it hits a collision, doesn't push the other t2dStaticSprites and the cursor can end up swimming over to the other object, thus swapping the t2dStaticSprites you are dragging, against your will.
Here is what I have, as I have used the system that this post was following:
function aSquare::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks) {
%this.setPosition(%worldPosition);
JD_SceneGraph.setLayerDrawOrder(%this, FRONT);
} //end of aSquare::onMouseDragged
function aSquare::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) {
if (%dstObj.class $= "aSquare") {
echo("--COLLIDED--"); }
} //end of aSquare::onCollision
Essentially everything is fine if I manually change the layers up in the Editor and test, but that's not the way to go at all. I tried FRONT, I tried FORWARD, it has no effect at all on runtime and no errors, but the collision is there, trying its hardest. Please help.
07/02/2011 (7:45 pm)
I have a mouse event, onMouseDragged on a t2dStaticSprite. Dragging works, collisions are set. I have 3 objects all of same class and datablock setup for em.What happens is that the order they were summoned to the stage is their order *within* the layer. If I drag one t2dStaticSprite that is more in front of another, the collision works, everything is fine (the t2dStaticSprite collides and drags all the objects under it along, sliding them, as if you were pushing little squares against each other off a table; However, reverse that ( drag a t2dStaticSprite that is behind another, over it ) and the collision is there, but the t2dStaticSprite fails to follow the cursor when it hits a collision, doesn't push the other t2dStaticSprites and the cursor can end up swimming over to the other object, thus swapping the t2dStaticSprites you are dragging, against your will.
Here is what I have, as I have used the system that this post was following:
function aSquare::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks) {
%this.setPosition(%worldPosition);
JD_SceneGraph.setLayerDrawOrder(%this, FRONT);
} //end of aSquare::onMouseDragged
function aSquare::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) {
if (%dstObj.class $= "aSquare") {
echo("--COLLIDED--"); }
} //end of aSquare::onCollision
Essentially everything is fine if I manually change the layers up in the Editor and test, but that's not the way to go at all. I tried FRONT, I tried FORWARD, it has no effect at all on runtime and no errors, but the collision is there, trying its hardest. Please help.
Torque Owner Dan Maruschak