Archive for April 6th, 2014

Collisions in OpenFL

Sunday, April 6th, 2014

Fallback or ‘alternate’ content goes here.
This content will only be visible if the SWF fails to load.

To detect if there is a collision among two sprites, it is possible to use the method hitTestObject( DisplayObject ) this way:


if ( moving_left ) {
direction = DIRECTION_LEFT;
x = x - 1;
}

for (child in 1...parent.numChildren ) {
if ( Std.is(parent.getChildAt(child), Wall) ) {
if ( parent.getChildAt(child).hitTestObject (this) ) {
x = x + 1;
}
}
}