change depths in as3
i´m trying to change depths of sprites that makes an elliptical movement.
to make some perspective i scaled the sprites according to their y position and i´m trying to change their depths dynamically.
As i expected swapDepths is no longer on AS3 so i tried to use setChildrenIndex() method, as adobe recommends. So the problem is that the index that i need to pass must be in range of the stage number of children. so i can´t pass just a Math.floor() of the y position of the sprites, ´cause it throws an error.
my pain is finding a way to calculate the correct depth of each sprite according to it´s y position
now i´ve got something like this on my onEnterFrame handler
i´m trying to find a way to calculate the correct index (or depth)...
// first define the angle of each element
sprites[i]._angle += speed;
// use sine and cosine to set the x and y position of each element, multiply by the radius factor and add the centerX value
sprites[i].x = Math.cos(sprites[i]._angle) * radiusX + centerX;
sprites[i].y = Math.sin(sprites[i]._angle) * radiusY + centerY;
// scale the sprites acoording to it's y position to create an illusion of some perstpective
s = sprites[i].y / (radiusY + centerY);
sprites[i].scaleY = sprites[i].scaleX = s;
sprites[i].alpha = s + 0.3;
depth = ???;
i imagine something like this (but not exactly this)
Math.floor(stage.numChildren / radiusY * sprites[i].y)
but i´s not good
is there an easy way to do it?
half as fun, double the price
You should be able to use swapChildren, if you have a reference to two sprites that you want in reverse order.
thanks a lot to you both :-)
Click Here to Expand Forum to Full Width
Poll by Flashkit.com