Class Director<C>

java.lang.Object
com.github.yellowstonegames.smooth.Director<C>
Type Parameters:
C - a type that contains or is otherwise associated with a Glider, such as a CoordGlider

public class Director<C> extends Object
Handles multiple objects that are each associated with a Glider, and allows starting and stopping the gliding animation for all of those objects at once. This must be given a ObjToObjFunction that can extract some form of Glider out of a C object; this is typically a method reference, such as to a getter. A Director has an Iterable of C objects, often an ObjectList or perhaps the Values collection of an ObjectObjectMap, that it will go through and update the Glider in each C. User code typically calls step() every frame; this is a no-op if the Director is not playing. If the Director is playing, then step() calculates the amount of the glide animation that has been completed, loops over each C in the Iterable, extracts a Glider from each C, calls Glider.setChange(float) on those Gliders with the calculated amount, and potentially calls stop() if the animation has completed. You get the Director playing with play(), and can pause it temporarily with pause() (you resume a paused Director with play() again), or stop the Director entirely with stop() (which sets it back to the beginning of the animation).
  • Field Details

    • extractor

      public com.github.tommyettinger.function.ObjToObjFunction<? super C, Glider> extractor
    • container

      public Iterable<C> container
    • playTime

      protected long playTime
    • playing

      protected boolean playing
    • duration

      protected long duration
    • elapsed

      protected long elapsed
  • Constructor Details

    • Director

      public Director(com.github.tommyettinger.function.ObjToObjFunction<? super C, Glider> fun)
    • Director

      public Director(com.github.tommyettinger.function.ObjToObjFunction<? super C, Glider> fun, Iterable<C> coll)
    • Director

      public Director(com.github.tommyettinger.function.ObjToObjFunction<? super C, Glider> fun, Iterable<C> coll, long durationMillis)
  • Method Details

    • play

      public void play()
    • pause

      public void pause()
    • stop

      public void stop()
    • step

      public void step()
    • isPlaying

      public boolean isPlaying()
    • getDuration

      public long getDuration()
      Gets the duration of each glide animation, in milliseconds. The default duration is 500 ms if unspecified.
      Returns:
      the duration of each glide, in milliseconds.
    • setDuration

      public void setDuration(long duration)
      Sets the duration of each glide, in milliseconds, and if the duration changed, calls stop(). The default duration is 500 ms if unspecified.
      Parameters:
      duration - how long each glide animation should take, in milliseconds
    • getContainer

      public Iterable<C> getContainer()
    • setContainer

      public void setContainer(Iterable<C> container)