View Full Version : Help with my 3d Class
soggybag
03-01-2008, 12:47 AM
I made up a simple 3d class in AS2 : http://www.webdevils.com/?p=9
I'd like to update this to AS3. I have everything working, but I ran into problem with setting the depths of clips.
In AS3 clips no longer have a depth. It seems the only way to set their depth is to move them in the display list with addChild().
The AS2 version of the script sets the depth of clips based on a Z depth property. It seems this method will not work is AS3.
I have the idea that I might need to make a class that runs in the back ground whose purpose is to organize the stacking of clips. I was thinking about making this a singleton class that is created when a 3d object is created.
Does this sound like a reasonable idea? Give me some suggestions. Maybe there is a better method to handle depths in AS3?
Bombdogs
03-01-2008, 02:33 AM
I think the easiest way would be just to sort the display list by the z property of each movie clip, every frame.
PMF
soggybag
03-01-2008, 03:21 AM
Yep you hit the nail on the head. The problem is that I designed the 3d Class so that extends MovieClip. Which means that every clip keeps track of it's own properties.
With the AS2 this worked well because each clip could set it's depth.
With AS3 a clip can't set a depth. Instead it can only be stacked in the display and there are no empty positions. Which makes me think that I would need a manager class to sort and arrange all 3d clips according to depth.
Then again maybe I'm missing something or do not have a full understand of the options for arranging things in the display list.
lordofduct
03-01-2008, 03:48 AM
childIndex is what you are looking to modify. It is a list of all the display objects and the order is the depth order. Now that it follows a standard array set up you can't just pop them in with some ambiguous number.... you have to figure out that order.
Do this, take the Z depth of each object and use that to figure out its depth. Then create an array of all the objects from closest to furthest using the z depth (just sort through them from lowest z to greatest z) and push them into the array in that order. Then sort the childindex with that array.
here senocular talks about sorting by the y value with a list of trees and explains the differences between AS2 and 3 with how they deal with depth:
http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=2
just adapt it to your use.
soggybag
03-01-2008, 05:05 AM
This looks like some good info. It seems to confirm my suspicions.
My class extends Movie Clip which means that each clip sets it's XYZ. This won't work for depth.
Which is why I'm thinking I should create singleton class that runs in the background and manages depth, call it depth manager. This class would be created by any instance of the 3d class. Each instance of 3d would register with Depth Manager and Depth manager would arrange all 3d clips each frame based on their Z value.
Bombdogs
03-01-2008, 11:16 AM
Yep, you definitely need some sort of manager class.
You *could* get each child to look at & sort it's parent display list, but that would be woefully inefficient with more than a couple of clips.
PMF
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.