Classes:DynamicValueInterpolator

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


DynamicValueInterpolator is a data-scoped class that allows for gradual change of a value, which can be used for something like a health indicator lerping over a few tics instead of changing its value instantly, or a similar effect with a graphical element. It can be used in any scope.

DynamicValueInterpolator is very similar to LinearValueInterpolator; the only difference is that it applies easing-in/easing-out effect to interpolation by performing differently-sized steps, whereas LinearValueInterpolator, as implied by its name, interpolates linearly.

Note, both interpolators update every tic regardless of the scope they were created from, so in UI scope this method will not be particularly smooth, since it'll still be tied to the default 35-tic framerate.

Fields

  • int mCurrentValue - The current value contained in the interpolator
  • int mMinChange - The minimum change from from the original value to the target value per interpolator's update
  • int mMaxChange - The maximum value from from the original value to the target value per interpolator's update
  • double mChangeFactor - The change factor

Methods

Static

static DynamicValueInterpolator Create(int startval, double changefactor, int minchange, int maxchange)

This function instantiates a new interpolator. It should be cast to a local field in the HUD (or other UI) class in order to interact with it.

Arguments:

  • int startval - The original value
  • double changefactor - The fraction of the amount between the current value and the target value the interpolator should cover per one Update() call
  • int minchange - The minimum change from from the original value to the target value per interpolator's update
  • int maxchange - The maximum value from from the original value to the target value per interpolator's update

Dynamic

  • void Update(int destvalue)
Updates the interpolator, setting a new target value for it to move towards from the current value. The new target value is defined by the destvalue argument.
  • int GetValue()
Returns the current value in the interpolator (contained in the mCurrentValue field).
  • void Reset(int value)
Sets the interpolator's current value to value.