Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: CollectibleHandler

[26:7] extends: CollisionHandler

Wraps FXGL's CollectibleHandler (com.almasb.fxgl.dsl.handlers.CollectibleHandler), a CollisionHandler subclass that handles the common pattern of a collector picking up a collectible: optional sound is played, a callback runs, and the collectible is removed. Register with the running game's PhysicsWorld (fxgl.getPhysicsWorld().addCollisionHandler in chunk 6). Example: h = new CollectibleHandler("player", "coin", "pickup.wav", ::collectCoin); physicsWorld.addCollisionHandler(h.obj); public collectCoin(coin) { fxgl.inc("score", 1); }

Methods

  • CollectibleHandler (string CollectorType, string CollectibleType, string SoundName = "", callback OnCollect = null)

    Creates a new CollectibleHandler.

    • @p CollectorType is the collector entity type.
    • @p CollectibleType is the collectible entity type.
    • @p SoundName is an asset name played on pickup (empty for no sound).
    • @p OnCollect is an optional callback (collectible) -> any.
  • adopt (object Ajo)

    Wraps an existing CollectibleHandler AussomJavaObject.

  • noop (c)

    Internal: zero-effect default action.