AS3 HitTestObject Issue w/ Array

Subscribe to AS3 HitTestObject Issue w/ Array 4 posts

avatar for caroger caroger 1 post
Flag Post

I am having a rough time figuring out why this will not work….. The energyPickUp is a class and it is part of var energyPickupList:Array = new Array();

what I would like to do, is have the (player) instance cause the pickup to remove itself on contact, but I can;t even get the trace to return for me :/

here is the code for the hittest… maybe I have something messed up… If you need any of the other parts of my code relating to the class I will give it to you. This is just the part specifically related to the array hittest.
(this is all inside the main game loop except for the array variable listed above)

if (energyPickupList.length > 0)
{
for (var m:int = 0; m < energyPickupList.length; m++)
{
if (energyPickupList[m].hitTestObject(player))
{
trace(“player touching energyPickup”);
energyPickupList[m].removeSelfHit(); playerHP = playerHP + energyPickupFill;
}
}
}

 
avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Your hitTest code seems to be ok. Are you sure you are adding energyPickUps to array? try tracing after:

if (energyPickupList.length > 0)
{

Or maybe a problem with loop?

 
avatar for a3lex33 a3lex33 127 posts
Flag Post

It could also be that player is not defined or defined incorrectly, be sure to check it again.

 
avatar for FlashGrenade FlashGrenade 246 posts
Flag Post

You could try putting your powerups in a vector instead of an array.

what does your powerup class look like anyway? can you put it up?