http://stackoverflow.com/questions/6409874/checking-for-a-collision-between-multiple-dynamic-instances-in-as3Okay, here's the rub. I'm making a little maze game. In this maze game, I have walls. They link to a class called Wall.as. In order to collision detect with the player, I do this:
MovieClip(parent).checkCollisonWithPlayer(this);
Where (parent) is a manager logic class. The parent does this
public function checkCollisonWithPlayer(wall:MovieClip)
{
if(player != null)
{
Collision.block(player,wall);
}
}
Now here's my problem. I have a class of Bullet.as that does much the same thing:
private function onEnterFrame(event:Event):void
{
x+= _vx;
//Check for collisions with walls and enemies
MovieClip(parent).checkCollisionWithEnemies(this);
//Remove if it leads off the stage
if (x > stage.stageWidth)
{
parent.removeChild(this);
}
}
What if I wanted to check for a collision between one of these bullets() and one of these walls()? How can I do that? They're never in the same function at the same time and there's almost certainly more than one of each in play at any time. I'm new to AS and this feels like a common issue, but I couldn;t dig up any material that made sense.
Here;s what I need:
public function checkCollisonWithWall(wall:MovieClip,bullet:MovieClip)
{
if(bullet.hitTestObject(wall))
Collision.block(bullet,wall);
}
}
But of course that doesn't work. What are my options?