How to check for collisions against an entire array?


(John Andersson) #1

Thanks :stuck_out_tongue:


(Martí Angelats i Ribera) #2

You can check it but it’s better to use the type property of Entity class


(John Andersson) #3

I have a huge collision array, and they have different types, so that’s why I need to check the array :stuck_out_tongue: How do I do it? And why is it better to check for the type?


(Martí Angelats i Ribera) #4

Does this array contain multiple types but all of the types are there? If you only want to check for multiple types you can do this:

collideType(["type1", "type2", "type3"], x, y);

If you really want to check from the array you have to do:

var collidable:Array; //the array with all the entities to test the collision

var collidingWith:Array = new Array;
collideTypeInto(["type1", "type2", "type3"], x, y, collidingWith); //You still have to put all the types af all the entities in the array

var colliding:Boolean = false;
var i:int = 0;
while (i < collidingWith.length && !colliding)
{
	colliding = (collidable.indexOf(collidingWith[i]) != -1;
	i++;
}

//colliding is the output

Edit: Forgot to increse the i.