The only method i can find in MotionEvent
that actually changes the position on the track is setTime(float)
.
Sane values lie between 0.0f
(0%) and initialDuration
(100%).
Each time you add a waypoint to a MotionPath
it will update the underlying Spline
, its total length and the lengths of each segment.
Using this information you can calculate the corresponding "time marks" for your waypoints:
public float calcWaypointTime(MotionPath path, MotionEvent motionEvent, int waypointIndex) {
// Distance between start and waypoint
float wpDistance = 0;
// Sum up segment lengths until waypoint is reached
List<Float> segLen = path.getSpline().getSegmentsLength();
for(int i=0; i<segLen.size() && i<waypointIndex; ++i)
wpDistance += segLen.get(i);
// Transform distance to time
return (wpDistance / path.getSpline().getTotalLength()) * motionEvent.getInitialDuration();
}