melonJS
    Preparing search index...

    Function setListener

    • Have the listener follow a camera or a renderable, every frame.

      Pass app.viewport and world-placed sounds pan and fade around the view with nothing else to write. Pass the player and they are heard from the character rather than the camera, which is usually what a scrolling game with a lagging camera wants. Pass null to stop, leaving the listener where it was.

      Where the ear goes depends on the target:

      • a Camera2d is heard from the CENTER of its view (worldView, so its offset and zoom count), not from its pos, which is the view's top-left corner.
      • a Camera3d is heard from its pos, which is its eye, and also contributes its ORIENTATION, so turning the camera swings the stereo image.
      • any other renderable is heard from getAbsolutePosition(), position only: its pos, which is where its anchorPoint sits. That is its center under the (0.5, 0.5) default of a Renderable or a Sprite, but its TOP-LEFT corner under the (0, 0) of an Entity or of any object loaded from Tiled.

      Following stops on its own if the target is destroyed, which a stage that owns its camera does on every state change.

      Parameters

      • target: Renderable | null

        what to follow, or null to stop following

      Returns void

      audio.setListener(app.viewport); // hear from the camera
      audio.setListener(player); // hear from the player
      audio.setListener(null); // stop following