AS3 HitTestObject Issue w/ Array

4 posts

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;
}
}
}

 
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?

 
Flag Post

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

 
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?