Class AnimLayer

java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.armature.AnimLayer

public final class AnimLayer extends Object
One track of animation on an Animator: it plays one clip at a time, blending smoothly from the last, over the joints in its mask. Layers are stacked in the order they were made, later ones on top.

A layer can be driven: a function asked every frame which motion should play, which the layer follows, blending whenever the answer changes. play(Motion) plays something regardless; once it ends (a LoopMode.ONCE clip, a repeat count, or stop()) the driver takes over again.

animator.layer("base").drive(ctx -> ctx.moving() ? WALK : IDLE);
animator.layer("arms", l -> l.mask(JointMask.of("arm_left", "arm_right")));
animator.layer("breath", l -> l.blend(LayerBlend.ADDITIVE).weight(0.6F)).play(Motion.loop("breathe"));
animator.layer("arms").play(Motion.once("wave"));
  • Method Details

    • name

      public String name()
    • blend

      public AnimLayer blend(LayerBlend blend)
    • mask

      public AnimLayer mask(JointMask mask)
    • weight

      public AnimLayer weight(float weight)
      How strongly it shows, 0 to 1, at once.
    • fadeWeight

      public AnimLayer fadeWeight(float weight, float seconds)
      Moves its weight to a new value over some seconds: fade a layer in or out as a whole.
    • weight

      public float weight()
    • speed

      public AnimLayer speed(float speed)
      Plays everything on this layer faster or slower, on top of each motion's own speed.
    • drive

      public AnimLayer drive(Function<ArmatureContext, @Nullable Motion> driver)
      Has the layer follow a function, asked every frame: whatever motion it returns plays, blending in when the answer changes; null blends back to rest (or to the layers below). Asking for the motion that is already playing changes nothing, so return constants, not new motions each time.
    • transition

      public AnimLayer transition(Transition transition)
      How animations on this layer blend into each other unless a rule or the motion says otherwise. Without one, the animator's default is used (Animator.transition), and without that Transition.DEFAULT.
    • transition

      public AnimLayer transition(String from, String to, Transition transition)
      How one clip blends into another on this layer: transition("run", "idle", Transition.freeze(0.4F)). Either name may be "*" for any clip; from is "*" too when nothing was playing. The most exact rule wins (both names, then from, then to), then the last one given.
    • transitions

      public AnimLayer transitions(TransitionRule rule)
      Picks transitions with code, before the pair rules and the default; return null to fall through to them.
    • transitions

      public AnimLayer transitions(boolean enabled)
      Turns blending on this layer on or off: off, every change cuts straight to the next animation, whatever the motions and rules say. On by default.
    • transitionsEnabled

      public boolean transitionsEnabled()
    • transitionTo

      public Transition transitionTo(Motion motion)
      The transition the next change to this motion would use, by the rules above.
    • play

      public AnimLayer play(Motion motion)
      Plays a motion now, setting the driver aside until it ends. Playing the clip that is already playing does nothing unless the motion restarts.
    • play

      public AnimLayer play(String clip)
      Plays a clip the way its file says to.
    • stop

      public AnimLayer stop()
      Blends out what play(Motion) started, back to the driver or to rest, the way it blended in.
    • stop

      public AnimLayer stop(float fadeSeconds)
    • isPlaying

      public boolean isPlaying()
      Whether a clip is playing and has not ended (a held last frame counts as ended).
    • isPlaying

      public boolean isPlaying(String clip)
    • clip

      @Nullable public @Nullable String clip()
      The clip playing, or null.
    • time

      public float time()
      Seconds into the clip playing.
    • progress

      public float progress()
      How far through the clip playing, 0 to 1.