2

I'm making a game with Haxe and the HaxeFlixel game engine, and I'm implementing collisions.

I found a way to check for collisions in the HaxeFlixel cheat sheet:

FlxG.overlap(ObjectOrGroup1, ObjectOrGroup2, myCallback);

private function myCallback(Object1:FlxObject, Object2:FlxObject):Void
{
}

But I don't like this style because the callback is separated from the function call. I would prefer this:

FlxG.overlap(ObjectOrGroup1, ObjectOrgroup2, function() {
    //do something
});

I saw this style in JavaScript, but I don't know exactly what it is. Is this possible in Haxe?

And I need this code like this:

if (FlxG.collide(Object1, Object2)) {
    //do something
}

It must return the value (true or false) and it processed by if statement.

Gama11
  • 31,714
  • 9
  • 78
  • 100
jun
  • 33
  • 4

1 Answers1

3

Your code snippet for the anonymous function is almost correct, but the callback function for FlxG.overlap() expects two arguments (the objects that collided). Try this:

FlxG.overlap(ObjectOrGroup1, ObjectOrGroup2, function(object1:FlxObject, object2:FlxObject) {
    // do something with object1 and object2
});
Gama11
  • 31,714
  • 9
  • 78
  • 100