Forums

ForumsProgramming Forum

Hittesting multiple movie clips with the same identifier? (AS2)

Posted Dec 13, '13 at 4:37pm

mightybob

mightybob

369 posts

Well somewhere I read that the more enterFrame's I use the more lag there will be.

So I am trying to make a lot of things be in 1 enterFrame, like coins.

So I need it to be so that when you hit a coin, it goes away, and you 1 point, just like it already does but so that I only need 1 enterFrame. Kind of like target objects in As3. But I don't know how to do this in as2â¦

Help?

 

Posted Dec 13, '13 at 6:23pm

weirdlike

weirdlike

714 posts

Moderator

Yes there should only be one loop(unless you need a "mini" loop that gets removed shortly)

how are you adding your movie clips? If everything is all added on the main timeline I think this might actually work for you

for(var i:int = 0; i < root.numChildren;i++)
{
if(HERO_MC.hitTestObject(root.getChildAt(i)))
{
trace(root.getChildAt(i));
}
}

without looking at your code of course. You will need to determine what movie clip is holding all the children. Maybe you have a hero that you add and a level_MC which contains all the enemies ground/walls whatever. "root" would be changed to level_MC

 

Posted Dec 14, '13 at 8:31am

mightybob

mightybob

369 posts

I'll try that out, thanks

 

Posted Dec 14, '13 at 9:43am

mightybob

mightybob

369 posts

Nope, get the error "Could not load the class or interface 'int""⦠Is int an as3 thing?

 

Posted Dec 14, '13 at 9:45am

mightybob

mightybob

369 posts

Wait, changed int to number no errors but how do I access the properties of the object I hit? Like X Y Alpha etc

 

Posted Dec 14, '13 at 11:27am

weirdlike

weirdlike

714 posts

Moderator

look at the trace that shows up when there is collision, it might just say "coin"

at that point you can get use name and make the function to suit

for(var i:int = 0; i < root.numChildren;i++)
{
if(HERO_MC.hitTestObject(root.getChildAt(i)))
{
var object = root.getChildAt(i);
if(object is coin)
{
//coin function
}
if(object is ground)
{
//ground function
}

}
}

 

Posted Dec 14, '13 at 12:38pm

mightybob

mightybob

369 posts

Oh, ok, in As2 wouldn't I need to do this though?

var object:MovieClip = getchildstuffblahblahâ¦

Anyways I will try both ways thanks for your help

 

Posted Dec 14, '13 at 1:33pm

weirdlike

weirdlike

714 posts

Moderator

well kinda, it in itself doesn't need to be declared as movieclip as it already is one. Replace the term "object" with anything you like

var interactiveObject = root.getChildAt(i);
if(interactiveObject is coin)

 

Posted Dec 14, '13 at 2:06pm

mightybob

mightybob

369 posts

ah, ok

 

Posted Dec 14, '13 at 2:23pm

mightybob

mightybob

369 posts

What the heck am I doing wrong here!?

Here is my code:

onEnterFrame = function() {

for(var i:Number = 0; i < coins.numChildren;i++)
{
if(char.hitTest(coins.getChildAt(i))==true)
{
trace(coins.getChildAt(i));
var object = coins.getChildAt(i);
if(object is coin)
{
coin._x = 100000;
trace("YOU WIN&quot;
}
}
}

}

And I get 2 errors:

Unexpected } encountered.

Expected ).

I have triple checked both and am not finding anything wrong

 
Reply to Hittesting multiple movie clips with the same identifier? (AS2)

You must be logged in to post a reply!