@Override public long getMaxSleepTime(Actor actor) { int subPeriod = timePeriodManager.getCurrentSubPeriod(); if (subPeriod == rotateUpSubPeriod || subPeriod == rotateDownSubPeriod) { return 0; } return timePeriodManager.getSubPeriodDuration(subPeriod) - timePeriodManager.getCurrentSubPeriodTime(); }
public void setDurations(long rotationDurationMillis, long stallDurationMillis) { timePeriodManager.reset(); int subPeriodCount = 0; timePeriodManager.addSubPeriod(rotationDurationMillis); rotateUpSubPeriod = subPeriodCount; subPeriodCount++; if (stallDurationMillis > 0) { timePeriodManager.addSubPeriod(stallDurationMillis); stallUpSubPeriod = subPeriodCount; subPeriodCount++; } timePeriodManager.addSubPeriod(rotationDurationMillis); rotateDownSubPeriod = subPeriodCount; subPeriodCount++; if (stallDurationMillis > 0) { timePeriodManager.addSubPeriod(stallDurationMillis); stallDownSubPeriod = subPeriodCount; } }
@Override public void control(Actor actor, float deltaSeconds) { long deltaMillis = (long) (deltaSeconds * 1000); timePeriodManager.update(deltaMillis); float angle; float normalizedValue; int subPeriod = timePeriodManager.getCurrentSubPeriod(); // Rotate up if (subPeriod == rotateUpSubPeriod) { normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime(); Interpolation interpolation = Interpolation.linear; if (this.interpolation != null) { interpolation = this.interpolation; } angle = interpolation.apply(minAngle, maxAngle, normalizedValue); } // Stall up else if (subPeriod == stallUpSubPeriod) { angle = maxAngle; } // Rotate down else if (subPeriod == rotateDownSubPeriod) { normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime(); Interpolation interpolation = Interpolation.linear; if (this.interpolation != null) { interpolation = this.interpolation; } angle = interpolation.apply(maxAngle, minAngle, normalizedValue); } // Stall up else { angle = minAngle; } actor.setRotation(angle); }
@Override public void reset() { timePeriodManager.reset(); interpolation = null; }