Collisions in OpenFL

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;
}
}
}

Tags:

2 Responses to “Collisions in OpenFL”

  1. Paco says:

    Aún no he conseguido salir del laberinto… :-/

  2. Alfredo says:

    Lo cierto es que el laberinto es lo que hay fuera. Lo que no has conseguido es entrar en el laberinto.

Leave a Reply


5 + = 7