Class Feedback

java.lang.Object
com.codename1.gaming.platformer.view.Feedback

public class Feedback extends Object

"Juice": what the player sees and hears when something happens, chosen per WorldEvent type -- the role of Corgi Engine's MMFeedbacks.

A Reaction bundles a camera shake, a screen flash, a sound name and a particle burst. PlatformView runs every event of every tick through #react, which shakes the GameCamera and hands the sound and the burst to a Sink the game supplies (a com.codename1.gaming.SoundPool, a com.codename1.gaming.ParticleEmitter, a haptic tap). The defaults make a level feel alive before any tuning: landings thud, stomps pop, hits shake.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    What one kind of event does.
    static interface 
    Receives what a reaction plays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates feedback with the stock reactions.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The flash color with its current opacity, 0 when none is showing.
    double
    How strong shakes, flashes and particle bursts are.
    void
    off(int eventType)
    Removes the reaction to an event type.
    on(int eventType)
    The reaction to an event type, created empty if it had none.
    void
    react(WorldEvent e, boolean aboutPlayer, GameCamera camera, Feedback.Sink sink)
    Plays an event.
    void
    setIntensity(double intensity)
    Scales every shake and flash, for an accessibility "reduce motion" setting.
    void
    update(double seconds)
    Fades the flash.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Feedback

      public Feedback()
      Creates feedback with the stock reactions.
  • Method Details

    • on

      public final Feedback.Reaction on(int eventType)

      The reaction to an event type, created empty if it had none.

      Parameters
      • eventType: a WorldEvent constant
      Returns

      the reaction to configure

    • off

      public void off(int eventType)

      Removes the reaction to an event type.

      Parameters
      • eventType: a WorldEvent constant
    • setIntensity

      public void setIntensity(double intensity)

      Scales every shake and flash, for an accessibility "reduce motion" setting.

      Parameters
      • intensity: 0 for none, 1 for full
    • getIntensity

      public double getIntensity()

      How strong shakes, flashes and particle bursts are.

      Returns

      0 for none, 1 for full

    • react

      public void react(WorldEvent e, boolean aboutPlayer, GameCamera camera, Feedback.Sink sink)

      Plays an event.

      Parameters
      • e: the event
      • aboutPlayer: whether the player is its subject
      • camera: shaken, may be null
      • sink: receives sounds and particles, may be null
    • update

      public void update(double seconds)

      Fades the flash.

      Parameters
      • seconds: time since the last frame
    • getFlash

      public int getFlash()

      The flash color with its current opacity, 0 when none is showing.

      Returns

      ARGB