Package tripleplay.ui.util
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>
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
Modifier and TypeFieldDescriptionreact.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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
onCancel
(Pointer.Interaction iact) void
onDrag
(Pointer.Interaction iact) void
onEnd
(Pointer.Interaction iact) void
onStart
(Pointer.Interaction iact) pythagoras.f.IPoint
position()
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
-
Field Details
-
friction
public float frictionThe deceleration (in pixels per ms per ms) applied to non-zero velocity. -
flickXfer
public float flickXferThe fraction of flick speed transfered to the entity (a value between 0 and 1). -
maxFlickSpeed
public float maxFlickSpeedThe maximum flick speed that will be transfered to the entity; limits the actual flick speed at time of release. This value is not adjusted byflickXfer
. -
maxClickDelta
public float maxClickDeltaThe maximum distance (in pixels) the pointer is allowed to travel while pressed and still register as a click. -
clicked
Signal dispatched when a pointer usage did not end up being a flick.
-
-
Constructor Details
-
XYFlicker
-
-
Method Details
-
position
public pythagoras.f.IPoint position()Gets the current position. -
onStart
- Overrides:
onStart
in classPointer.Listener
-
onDrag
- Overrides:
onDrag
in classPointer.Listener
-
onEnd
- Overrides:
onEnd
in classPointer.Listener
-
onCancel
- Overrides:
onCancel
in classPointer.Listener
-
update
public void update(float delta) -
reset
public void reset(float maxX, float maxY) Resets the flicker to the given maximum values. -
positionChanged
public void positionChanged(float x, float y) Sets the flicker position, in the case of a programmatic change.
-