Class XYFlicker

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

public class XYFlicker extends Pointer.Listener
Translates pointer input on a layer into an x, y offset. With a sufficiently large drag delta, calculates a velocity, applies it to the position over time and diminishes its value by friction. For smaller drag deltas, dispatches the pointer end event on the clicked signal.

NOTE:Clients of this class must call update(float), so that friction and other calculations can be applied. This is normally done within the client's own update method and followed by some usage of the position() method. For example:


    Layer layer = ...;
    XYFlicker flicker = new XYFlicker(layer);
    { layer.addListener(flicker); }
    void update (int delta) {
        flicker.update(delta);
        layer.setTranslation(flicker.position().x(), flicker.position().y());
    }
 
TODO: figure out how to implement with two Flickers. could require some changes therein since you probably don't want them to have differing states, plus 2x clicked signals is wasteful
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    react.Signal<Pointer.Event>
    Signal dispatched when a pointer usage did not end up being a flick.
    float
    The fraction of flick speed transfered to the entity (a value between 0 and 1).
    float
    The deceleration (in pixels per ms per ms) applied to non-zero velocity.
    float
    The maximum distance (in pixels) the pointer is allowed to travel while pressed and still register as a click.
    float
    The maximum flick speed that will be transfered to the entity; limits the actual flick speed at time of release.
  • Constructor Summary

    Constructors
    Constructor
    Description
    XYFlicker(Layer scrollLayer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    void
     
    void
     
    pythagoras.f.IPoint
    Gets the current position.
    void
    positionChanged(float x, float y)
    Sets the flicker position, in the case of a programmatic change.
    void
    reset(float maxX, float maxY)
    Resets the flicker to the given maximum values.
    void
    update(float delta)
     

    Methods inherited from class playn.scene.Pointer.Listener

    onEmit

    Methods inherited from class react.Slot

    andThen, compose, filtered, onChange

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • friction

      public float friction
      The deceleration (in pixels per ms per ms) applied to non-zero velocity.
    • flickXfer

      public float flickXfer
      The fraction of flick speed transfered to the entity (a value between 0 and 1).
    • maxFlickSpeed

      public float maxFlickSpeed
      The maximum flick speed that will be transfered to the entity; limits the actual flick speed at time of release. This value is not adjusted by flickXfer.
    • maxClickDelta

      public float maxClickDelta
      The maximum distance (in pixels) the pointer is allowed to travel while pressed and still register as a click.
    • clicked

      public react.Signal<Pointer.Event> clicked
      Signal dispatched when a pointer usage did not end up being a flick.
  • Constructor Details

    • XYFlicker

      public XYFlicker(Layer scrollLayer)
  • Method Details