public class Motion
- Object
- Motion
Abstracts the notion of physical motion over time from a numeric location to another. This class can be subclassed to implement any motion equation for appropriate physics effects.
This class relies on AnimationTime.now() to provide transitions between coordinates, allowing the underlying clock to be overridden for deterministic playback or custom animation pacing. The motion can be subclassed to provide every type of motion feel from parabolic motion to spline and linear motion. The default implementation provides a simple algorithm giving the feel of acceleration and deceleration.
Constructors
protected Motion(int sourceValue, int destinationValue, int duration) | Construct a point/destination motion |
protected Motion(int sourceValue, float initVelocity, float friction) | Construct a velocity motion |
protected Motion(int sourceValue, double initVelocity, double friction) |
Methods
Inherited methods
Constructor details
Motion
protected Motion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
Motion
protected Motion(int sourceValue, float initVelocity, float friction)Parameters
sourceValueint- starting value
initVelocityfloat- initial velocity
frictionfloat- degree of friction
Motion
protected Motion(int sourceValue, double initVelocity, double friction)Method details
isSlowMotion
public static boolean isSlowMotion()Returns
setSlowMotion
public static void setSlowMotion(boolean aSlowMotion)Parameters
aSlowMotionboolean- the slowMotion to set
createCubicBezierMotion
public static Motion createCubicBezierMotion(int sourceValue, int destinationValue, int duration, float p0, float p1, float p2, float p3)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
p0float- argument to the bezier function
p1float- argument to the bezier function
p2float- argument to the bezier function
p3float- argument to the bezier function
Returns
createThreePointCubicMotion
public static Motion createThreePointCubicMotion(int sourceValue, int destinationValue, int duration, float a1X, float a1Y, float b1X, float b1Y, float midX, float midY, float a2X, float a2Y, float b2X, float b2Y)A curve made of TWO cubic beziers joined at a point, which a single cubic cannot express.
A plain cubic-bezier is monotonic in a way some motion is not: it cannot
accelerate hard, ease, and then ease out again, because it has only two control
points to spend. Curves that do this are specified as a pair of beziers meeting at
a midpoint, each with its own controls, and the joint is where the character of
the motion changes.
The segments are evaluated in their own normalized space and rescaled, so each half is an ordinary CSS cubic-bezier and the two meet exactly at the midpoint.
Parameters
sourceValueint- the initial value
destinationValueint- the value at the end of the motion
durationint- the motion duration in milliseconds
a1Xfloat- ,
a1Y,b1X,b1Y: control points of the first segment a1Yfloat- Not documented.
b1Xfloat- Not documented.
b1Yfloat- Not documented.
midXfloat- ,
midY: the point the two segments meet at midYfloat- Not documented.
a2Xfloat- ,
a2Y,b2X,b2Y: control points of the second segment a2Yfloat- Not documented.
b2Xfloat- Not documented.
b2Yfloat- Not documented.
Returns
createEaseInOutMotion
public static Motion createEaseInOutMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
Returns
createEaseMotion
public static Motion createEaseMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
Returns
createEaseInMotion
public static Motion createEaseInMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
Returns
createEaseOutMotion
public static Motion createEaseOutMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- starting value
destinationValueint- destination value
durationint- motion duration
Returns
createLinearMotion
public static Motion createLinearMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- the number from which we are starting (usually indicating animation start position)
destinationValueint- the number to which we are heading (usually indicating animation destination)
durationint- the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns
createLinearColorMotion
public static Motion createLinearColorMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- the color from which we are starting
destinationValueint- the destination color
durationint- the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns
createSplineMotion
public static Motion createSplineMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- the number from which we are starting (usually indicating animation start position)
destinationValueint- the number to which we are heading (usually indicating animation destination)
durationint- the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns
createDecelerationMotion
public static Motion createDecelerationMotion(int sourceValue, int destinationValue, int duration)Parameters
sourceValueint- the number from which we are starting (usually indicating animation start position)
destinationValueint- the number to which we are heading (usually indicating animation destination)
durationint- the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns
createCriticalDampedSpringMotion
public static Motion createCriticalDampedSpringMotion(int sourceValue, int destinationValue, int duration)x(t) = dst - (dst - src) * (1 + w*t) * e^(-w*t) where w is chosen so the residual
at t=duration is about 2%. Produces a quick initial approach with a soft settling
tail, closer in feel to the iOS rubber-band snap-back than the quadratic
createDecelerationMotion curve.Parameters
sourceValueint- the number from which we are starting
destinationValueint- the number to which we are heading
durationint- the length in milliseconds of the motion
Returns
createDecelerationMotionFrom
public static Motion createDecelerationMotionFrom(Motion motion, int maxDestinationValue, int maxDuration)Parameters
motionMotion- the number from which we are starting (usually indicating animation start position)
maxDestinationValueint- The farthest position to allow motion to go.
maxDurationint- The longest that the duration is allowed to proceed for.
Returns
createFrictionMotion
public static Motion createFrictionMotion(int sourceValue, int maxValue, float initVelocity, float friction)Parameters
sourceValueint- the number from which we are starting (usually indicating animation start position)
maxValueint- the maximum value for the friction
initVelocityfloat- the starting velocity
frictionfloat- the motion friction
Returns
createExponentialDecayMotion
public static Motion createExponentialDecayMotion(int sourceValue, int maxValue, double initVelocity, double timeConstant)finish
public void finish()start
public void start()getCurrentMotionTime
public long getCurrentMotionTime()Returns
setCurrentMotionTime
public void setCurrentMotionTime(long currentMotionTime)Parameters
currentMotionTimelong- the time in milliseconds for the motion.
isDecayMotion
public boolean isDecayMotion()isFinished
public boolean isFinished()Returns
getValue
public int getValue()Returns
getVelocity
public double getVelocity()Gets an approximation of the current velocity in pixels per millisecond.
NOTE: If #countAvailableVelocitySamplingPoints() 0
Returns
countAvailableVelocitySamplingPoints
public int countAvailableVelocitySamplingPoints()#getVelocity(). A minimum of 2 sampling
points are required for the result of #getVelocity() to have any meaning.Returns
#getVelocity().getSourceValue
public int getSourceValue()Returns
setSourceValue
public void setSourceValue(int sourceValue)Parameters
sourceValueint- the source value
getDestinationValue
public int getDestinationValue()Returns
getStartTime
protected long getStartTime()Returns
setStartTime
public void setStartTime(long startTime)Parameters
startTimelong- the starting time
getDuration
public int getDuration()