Reputation: 7460
I am creating a game in which the character leaves a trail of moveclips(I call them logs) as it walks. After it reaches it's objective, the character needs to go back and pick up all the movieclips he left (not necessarily in the order he left them). The way I am doing it, it only picks up one and I can't figure out what I should do to be able to pick up every one of them. Here is my code for generating the logs:
this["log"+counter] = new _Log();
addChild(this["log"+counter]);
this["log"+counter] .x = char.x;
this["log"+counter] .y = char.y;
logCounter=0;
counter ++;
And here is how I am picking them up:
if(char.hitTestPoint(this["log"+(counter-1)] .x,this["log"+(counter-1)] .y, true)){
this["log"+(counter-1)] .visible = false;
this["log"+(counter-1)] .active = false;
}
And idea I had was if I could somehow test all the numbers between 1 and the current counter value at once while using the hitTestPoint function. Is there any way for me to do that? If not, what other ways you'd suggest for me to be able to pick up my trail of movieclips?
Thank you very much
Upvotes: 0
Views: 163
Reputation: 936
According your code you need check collisions in loop for all necessary logs:
for (var i:int=0; i<counter; i++)
{
if(char.hitTestPoint(this["log"+i].x,this["log"+i].y, true)){
this["log"+i].visible = false;
this["log"+i].active = false;
}
}
Upvotes: 2