开发者

AS3 - Using Matrix3D objects for reordering display

I'm working with about 20 objects that are moving around in 3D space. Adobe recommends "Using Matrix3D objects for reordering display":

  1. Use the getRelativeMatrix3D() method of the Transform object to get the relative z-axes of the child 3D display objects.

  2. Use the removeChild() method to remove the objects from the display list.

  3. Sort the display objects based on their relative z-axis values.

  4. Use the addChild() method to add the children back to the display list in reverse order.

Great. That's fine if the objects aren't moving. But what if there are animations happening and one object comes in front of another in z-space? The objects are displayed accoring to the position in the display list, not according to their z-order. How can you make objects respect z-order while animating (make object A appear in front of object B if object A's z-value 开发者_Go百科becomes smaller than object B)? Obviously you can't clear the display list during an animation.


It's practically the same as adobe's docs says... and it works perfectly for moving objects.

The simplest way, so you have some code reference, and given you have all of your 3d objects in an array, would go something like this:

function zSort(objects:Array) {
    objects.sortOn("z", Array.DESCENDING | Array.NUMERIC); // sort the array on the "z" property
    for each(var clip:DisplayObject in objects) { //loop the array and add the childs in the corrected order...
        addChild(clip);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜