Easily collideTypes from world class


(Bora Kasap) #1

i wish to use something like this in world class update function

var clickables:Array = ["emitter","absorber","battery"];
var entity:Entity = this.collidePoint(clickables, FP.world.mouseX, FP.world.mouseY);

but i see it’s not possible easily because of multiplying type strings as an array in “collidePoint” function.

So, why we don’t have that feature?

Am i have to use that?

var entity:Entity = this.collidePoint("emitter", FP.world.mouseX, FP.world.mouseY);
if (entity == null) entity = this.collidePoint("absorber", FP.world.mouseX, FP.world.mouseY);
if (entity == null) entity = this.collidePoint("battery", FP.world.mouseX, FP.world.mouseY);

Or am i have to make an entity to follow mouse cursor to check multiple collide types from that entity to use collideTypes as a point?

If that’s not my miss, i should suggest that feature for FP’s further versions…


(Jacob Albano) #2

You can use the collidePointInto() function for this.

var atPoint:Array = [];
var clickables:Array = ["emitter", "absorber", "battery"];

for each (var t:String in clickables)
{
    collidePointInto(t, mouseX, mouseY, atPoint);
}

for each (var e:Entity in atPoint)
{
    // do stuff
}


(Bora Kasap) #3

Hah, no no, that’s not my need.

I have no any entities placed at same position. Each one of my entities at a different position in the world.

you can see, i’m not grouping entities, i need only 1 entity, i’m trying to check for another type if collision returns null here;

var entity:Entity = this.collidePoint("emitter", FP.world.mouseX, FP.world.mouseY);
if (entity == null) entity = this.collidePoint("absorber", FP.world.mouseX, FP.world.mouseY);
if (entity == null) entity = this.collidePoint("battery", FP.world.mouseX, FP.world.mouseY);

(Jacob Albano) #4

Right, so you grab all the entities at a point and loop through them. Since you want to check each type until you get a valid collision, you just stop at the first one you care about.

You could even do it this way:

// previous code

var e:Entity = atPoint[0];
if (atPoint != null)
{
    // first entity you're interested in
}

This is the same as doing a series of checks like you have in your example.


(Bora Kasap) #5

Thanks, but i have no idea why FP have this feature in Entity but not in World… :confused:


(Jacob Albano) #6

What do you mean? These functions are all on World.


(Bora Kasap) #7

I mean collideTypes function

something like collidePointTypes