PDA

View Full Version : hitTesting with array



H4T
December 13th, 2004, 11:47 AM
I have a simple FOR loop which runs through an array of MC names, which runs fine, but I'm trying to use these names inside this array as hittest values. So, I have one MC, and the code in this MC runs through an array and checks for any collisions between it and the mc in the array.



for(k=0; k<herbNames.length; k++) {
if(name.hitTest(herbNames[k])) {
trace(name+" hit "+herbNames[k]);
}
}

So, how should I do the hitTest? Here is my idea, but because of the size of the mcs involved, I don't want to sit around all day waiting for the correct collisions to occur, lol. Here is what I had in mind..



if(name.hitTest(herbNames[k])) {
trace("Collision!");
}

Would that work? Or...something else? Is there maybe a more effecient way to do this (maybe a FOR...IN loop?)?

H4T
December 14th, 2004, 10:59 AM
*bump*

icio
December 14th, 2004, 05:01 PM
for(k=0; k<herbNames; k++) {
if(name.hitTest(herbNames[k])) {
trace(name+" hit "+herbNames[k]);
}
}

herbNames.length would return how many variables there are inside the array, we want to return an object for use with 'for (.in.)..' loops.

hope this helps :thumb:

H4T
December 14th, 2004, 06:40 PM
Really? Well I wanted that loop to run as many times as there are MCs, and since all the MCs are referenced inside the array, I thought if I simply counted the number of values in the array, I'd have the number of times I have to run through the loop?

Because the k must be less than a certain number, not an MC....those aren't the same data types?

icio
December 14th, 2004, 06:58 PM
actually, looking back on that, i have no idea what i was talking about - lol :lol:
ok, so here's what i'm thinking now:

for (k = 0; k < herbNames.length; k++) {
herb = herbNames[k];
if(name.hitTest(this[herb])) {
trace(name+" hit "+this[herb]);
}
}

hope this helps :thumb:

H4T
December 15th, 2004, 10:50 AM
Yessss!!11 Hehe, thanks, I've got it working now...I also edited the code to have the variable "name" be the full path to the mc (_level0.[whatever..]) and the collisions all work. I'm so happy, lol, been working on this problem for about a week. Thanks!

icio
December 15th, 2004, 11:28 AM
no problem. happy to help =)