public final class InterpolatedValue<T>
extends java.lang.Object
An interpolated value stores the initial value as well as the current value of a variable. During the interpolation phase, the interpolated value will be used for display.
// Example: Updating health stored as a struct InterpolatedValue<Health> health = mHealth.get(entityId).health; Health currentHealth = health.getCurrentValue(); // Set initial value prior to any changes health.getInitialValue().set(currentHealth); // Update current value currentHealth.hp = Math.min(currentHealth.hp + 5f, currentHealth.maxHp); // To use the interpolated value Health flyweight = new Health(); health.getInterpolatedValue(flyweight, 0.5f); // mid-way flyweight.hp;
Constructor and Description |
---|
InterpolatedValue(Interpolator<T> interpolator,
T initialValue,
T currentValue)
Constructor for the
InterpolatedValue |
Modifier and Type | Method and Description |
---|---|
T |
getCurrentValue()
Get the current value
|
T |
getInitialValue()
Get the initial value
|
void |
getInterpolatedValue(T flyweight,
float alpha)
Sets the flyweight to the interpolated value at the specified alpha
|
public InterpolatedValue(Interpolator<T> interpolator, T initialValue, T currentValue)
InterpolatedValue
interpolator
- the interpolator functioninitialValue
- the initial valuecurrentValue
- the current valuepublic T getInitialValue()
public T getCurrentValue()
public void getInterpolatedValue(T flyweight, float alpha)
flyweight
- the flyweight for the interpolated valuealpha
- the alpha is a value between 0.0f
and 1.0f