Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: CollisionHandler

[27:7] extends: FxObj

Wraps an AussomCollisionHandler (subclass of FXGL's abstract CollisionHandler) so Aussom code can react to collisions between entities of named types. The two type strings passed to the constructor identify the colliding entity types and order the pair the callbacks receive. Register the resulting handler with the running game's PhysicsWorld (fxgl.getPhysicsWorld().addCollisionHandler in chunk 6). Example: h = new CollisionHandler("player", "enemy"); h.onCollisionBegin(::onPlayerHit); physicsWorld.addCollisionHandler(h.obj); public onPlayerHit(player, enemy) { ... }

Methods

  • CollisionHandler (string TypeA, string TypeB)

    Creates a new CollisionHandler for the given pair of entity type strings. The handler fires only for collisions between the two types; entity A in callbacks always matches TypeA.

    • @p TypeA is the first entity type.
    • @p TypeB is the second entity type.
  • onCollisionBegin (callback Cb)

    Registers the onCollisionBegin callback (fires the first tick the entities collide). The callback receives (entityA, entityB).

    • @p Cb is a callback that takes two Entity arguments.
    • @r this object
  • onCollision (callback Cb)

    Registers the onCollision callback (fires every tick the entities remain in contact). The callback receives the pair.

    • @p Cb is a callback that takes two Entity arguments.
    • @r this object
  • onCollisionEnd (callback Cb)

    Registers the onCollisionEnd callback (fires the tick contact ends).

    • @p Cb is a callback that takes two Entity arguments.
    • @r this object
  • onHitBoxTrigger (callback Cb)

    Registers an onHitBoxTrigger callback that fires when two entities' HitBoxes start overlapping. The callback receives (entityA, entityB, hitBoxA, hitBoxB).

    • @p Cb is a callback (entityA, entityB, boxA, boxB) -> void.
    • @r this object