EightySeven
03-04-2009, 02:15 AM
Hey ya'll this is what I got. It works fine for what I need it to do right now but I'd like it to improve on it. So I offer it to the community for suggestions
//...In the game loop
for (var i:int = 0; i<gang.length; i++) {
DepthControl(gang[i]);
}
//...
//The functions was built to move an object backwards in the display list depending on its y position.
//so if the Y value is lower it should be behind objects with a higher y position
private function DepthControl(mc:MovieClip) {
var mcDepth:int = gameLevel.getChildIndex(mc);
for (var i:int; i < gameLevel.numChildren; i++) {
var child = gameLevel.getChildAt(i);
if (child is Table || child is Bar ) {
if (child.y < mc.y) {
if (gameLevel.getChildIndex(mc) < i) {
gameLevel.setChildIndex(mc, i+1);
}
}
if (child.y > mc.y) {
if (gameLevel.getChildIndex(mc) > i) {
gameLevel.setChildIndex((mc), i);
}
}
}
}
}
The only major issue I have with it right now is that when I add || child is Mutant to the outer most if statement it get an index out of range error on the line
gameLevel.setChildIndex(mc, i+1);
Mutants are dynamically created and added to the level.
Any thoughts on improvement or how to correct my issues with the current function would be greatly appreciated
//...In the game loop
for (var i:int = 0; i<gang.length; i++) {
DepthControl(gang[i]);
}
//...
//The functions was built to move an object backwards in the display list depending on its y position.
//so if the Y value is lower it should be behind objects with a higher y position
private function DepthControl(mc:MovieClip) {
var mcDepth:int = gameLevel.getChildIndex(mc);
for (var i:int; i < gameLevel.numChildren; i++) {
var child = gameLevel.getChildAt(i);
if (child is Table || child is Bar ) {
if (child.y < mc.y) {
if (gameLevel.getChildIndex(mc) < i) {
gameLevel.setChildIndex(mc, i+1);
}
}
if (child.y > mc.y) {
if (gameLevel.getChildIndex(mc) > i) {
gameLevel.setChildIndex((mc), i);
}
}
}
}
}
The only major issue I have with it right now is that when I add || child is Mutant to the outer most if statement it get an index out of range error on the line
gameLevel.setChildIndex(mc, i+1);
Mutants are dynamically created and added to the level.
Any thoughts on improvement or how to correct my issues with the current function would be greatly appreciated