-
[QUESTION] Resetting setChildIndex
I used setChildIndex in my game to cause the enemies to fall behind another graphic, and it works beautifully. However, the game is set up so when the player wins or loses, they have the option to play another game. When the player selects this option though, the enemies move behind the entire background. Therefore, I assume that the index is not resetting when the new game starts. So my question is, is there a way to reset the index so that when the setChildIndex is encountered again the enemies are where they are supposed to be?
-
Senior Member
You should be removing all the enemies from the displayList when the game ends, and then adding them back on when the player restarts anyways. It should work then.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
That's what I'm trying to figure out how to do, but the enemies are added within a function that activates on a timer, so I'm trying to figure out how to work with that. Here is the function so you can see what is going on.
tm.start();
function onstart (e:Event){
em.Sprite = new enemy();
em.x=Math.random()*550;
addChild(em);
//setChildIndex(em, 1);
}
That is how they are added, so now I am trying to figure out how to remove them so they are added again.
-
Senior Member
You should keep track of the enemies in an array, and then simply loop through that array and remove each of them when you're done with them.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
I will give it a shot. Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|