Minor bug found in Entity.getEntitiesByClass()

19 views
Skip to first unread message

Balthazar Auger

unread,
Mar 30, 2014, 9:24:18 PM3/30/14
to aw...@googlegroups.com
Hi!

While implementing a collision test for a drag and drop behavior, I wanted to use getEntitiesByClass to narrow down candidates for collision testing a bit. 

Strangely, the array always came out empty, no matter what combination of parameters I used, so I dug in a little further, doing a step by step analysis of the method.

When you bubble down in the for loop,

for ( i in l_entities )
{
if ( Std.is( i, p_classType ) )
{
l_result.push( cast i );
}
if ( p_isBubbleDown )
{
l_result.concat( i.getEntitiesByClass( p_classType, p_agenda, true ) );
}
}

results that match the class type are correctly added to the result array, but when we get back to the upper level of recursion, the result array comes back empty.

It turns out that Array.concat() returns the concatenated array, but doesn't modify the calling instance. So the results weren't being stored anywhere after concatenation.

To fix this method, you would need to change the following lines of Entity.hx (my additions are underlined)

254:
l_result = l_result.concat( i.getEntitiesByClass( p_classType, p_agenda, true ) );

259:
l_result = l_result.concat( parent.getEntitiesByClass( p_classType, p_agenda, false, true ) );

Once you do that, getEntitiesByClass returns what it is supposed to.

Rob Fell

unread,
Mar 31, 2014, 1:09:21 PM3/31/14
to aw...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages