-
Delete Object from Array
Hi!
I have many objects(movieclips) on my stage and I put them in an array
Actionscript Code:
for(var i = 0; i<numChildren; i++) { if(getChildAt(i) is MC) { mcarray.push(getChildAt(i)); } }
so I can do a hittest on them.
then when I go to the next level (let's say from level 1 to level 2) there are again multiple objects from the class MC that go into that array. i believe that the objects from level 1 are still in my 'mcarray'. how can i remove just the ones from level 1?
each time i go to another level the game lags more and more and i really need to fix that.
thanks for the help!
-
If you want mcarray to only contain stuff from the new level, you can either remove everything from it:
Code:
while (mcarray.length > 0){
mcarray.pop();
}
Or, if you don't need mcarray to point to the same actual array, you can just set it to a new empty array:
If mcarray contains things you need to keep, then you'll need a way of determining whether to keep or discard an object.
Code:
for (var i:int = mcarray.length-1; i >=0; i--){
if (shouldDiscard(mcarray[i])){
mcarray.splice(i, 1);
}
}
where you need to define the shouldDiscard function.
-
i'd do it like this:
delete the whole array and in the next frame put the same code...i've seen it on a tutorial for beginners somewhere. not sure how to explain it though.
sorry, i can't seem to find it but it was somewehere on here:
http://www.newgrounds.com/bbs/forum/2
you should take a look at the tutorials
Last edited by alexAAA; 05-26-2012 at 10:32 AM.
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
|