Class Flicker

java.lang.Object
react.Slot<Object>
playn.scene.Pointer.Listener
tripleplay.anim.Flicker
All Implemented Interfaces:
react.Reactor.RListener, react.SignalView.Listener<Object>, react.ValueView.Listener<Object>

public class Flicker extends Pointer.Listener
Implements click, and scroll/flick gestures for a single variable (y position by default). When the pointer is pressed and dragged, the scroll position is updated to track the pointer. If the last two pointer events describe a motion of sufficiently high velocity, the scroll position is "flicked" and undergoes (friction decelerated) motion. If the pointer is pressed and released without scrolling or flicking, the clicked signal is emitted.

To use: create a flicker, configure it as a pointer listener on a layer that represents your touchable area, then use position to position your flickable layer (or to offset your hand-drawn flickable elements) on every frame tick. You must also connect onPaint to a paint signal (to process changes due to acceleration and velocity).

Various flick parameters can be customized by overriding the appropriate method: friction(), maxFlickVel(), etc.

  • Field Details

    • min

      public float min
      This flicker's bounds.
    • max

      public float max
      This flicker's bounds.
    • position

      public float position
      The current position value.
    • changed

      public react.Signal<Flicker> changed
      A signal emitted when this flicker's position has changed.
    • clicked

      public react.Signal<Pointer.Interaction> clicked
      A signal that is emitted (with the pointer end event) on click.
    • enabled

      public react.Value<Boolean> enabled
      Whether or not this flicker is enabled (responding to pointer events). Disabling a flicker does not stop any existing physical behavior, it just prevents the user from introducing any further behavior by flicking or tapping.

      Note that if a pointer interaction has already started when the flicker is disabled, that interaction will be allowed to complete. Otherwise the flicker would be left in an unpredictable state.

    • onPaint

      public react.Slot<Clock> onPaint
      This must be connected to a paint signal.
  • Constructor Details

    • Flicker

      public Flicker(float initial, float min, float max)
      Creates a flicker with the specified initial, minimum and maximum values.
  • Method Details

    • connect

      public Flicker connect(react.Signal<Clock> paint)
      Connects this flicker to the paint signal.
    • posValue

      public Animation.Value posValue()
      Returns the position of this flicker as an animation value.
    • stop

      public void stop()
      Stops any active movement of this flicker. The position is immediately clamped back into min/max which may be jarring if the flicker was in the middle of a rebound and outside its bounds.
    • freeze

      public void freeze()
      Aborts any active movement of this flicker. Zeroes out velocity and resets state to stopped. This differs from stop() in that it does not clamp the flicker's position back into min/max, so it should only be used if you plan to subsequently manually adjust the position to reflect valid values. Otherwise you may freeze the flicker while it's in a rebound state and not inside its normal bounds.
    • onStart

      public void onStart(Pointer.Interaction iact)
      Overrides:
      onStart in class Pointer.Listener
    • onDrag

      public void onDrag(Pointer.Interaction iact)
      Overrides:
      onDrag in class Pointer.Listener
    • onEnd

      public void onEnd(Pointer.Interaction iact)
      Overrides:
      onEnd in class Pointer.Listener