• Runtimes
  • [Corona] How to change animation with mixing?

  • تم التحرير
Related Discussions
...

How can I change the animation at runtime (i.e. depends what user is doing what is next animation) using the "mixing" concept, and without having to pre-program the mixing times based on from-to animation pairs? I'm using Corona.

In fact just a way to instead of just having the "setAnimationByName (trackIndex, animationName, loop)" function available, to be able to pass the mix time to it as well, so it mixed the current running animation with the new incoming animation, like:

    "setAnimationByName (trackIndex, animationName, loop, mixinTime)"

Issue: Currently I'm using "state:setAnimationByName(0, animationName, true)" to change animations, however there is an abrupt change at this point. Really need the smoothing effect of mixing I'm seeing. I don't think I can use the "AnimationState" approach (??) as it seems to require you pre-program the mix times for each permutation of old-to-new-transition, which would be many in my case.

Note: I see in the Java workshop there is something that seems close to what I want. Is this the answer / is this possible in Corona? It's doesn't seem ideal as it seems you have to load each animation via json separately?

   public void create () {
      batch = new SpriteBatch();
      renderer = new ShapeRenderer();

  atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas"));
  SkeletonJson json = new SkeletonJson(atlas);
  SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-skeleton.json"));
  walkAnimation = json.readAnimation(Gdx.files.internal("spineboy/spineboy-walk.json"), skeletonData);   // **** HERE *** 
  jumpAnimation = json.readAnimation(Gdx.files.internal("spineboy/spineboy-jump.json"), skeletonData);   // **** HERE *** 
  skeleton = new Skeleton(skeletonData);
  root = skeleton.getRootBone();
  root.setX(250);
  root.setY(20);
  skeleton.updateWorldTransform();
   }

   public void render () {
      time += Gdx.graphics.getDeltaTime() / 6;
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      batch.begin();
      walkAnimation.apply(skeleton, time, true);
      if (time > 1) {
         float jumpTime = time - 1;
         float mixTime = 0.4f;
         if (jumpTime > mixTime)
            jumpAnimation.apply(skeleton, jumpTime, false);    // **** HERE *** 
         else
            jumpAnimation.mix(skeleton, jumpTime, false, jumpTime / mixTime);  // **** HERE *** 
         if (time > 4) time = 0;
      }
      skeleton.updateWorldTransform();
      skeleton.draw(batch);
      batch.end();
   }

You can set a default mix for your states and then just set a custom mix for the ones that need it, making the list much smaller.

something along the lines of stateData.defaultMix = float;
https://github.com/EsotericSoftware/spi ... ta.lua#L37

mixedup wrote

the Java workshop there is something that seems close to what I want. Is this the answer / is this possible in Corona? It's doesn't seem ideal as it seems you have to load each animation via json separately?

This code is old, the skeleton and animations are now stored in one file. You can use the Animation API directly instead of the AnimationState convenience class to have full control over mixing.

When using AnimationState, if the default mix Shiu mentioned is not enough, you could also override the AnimationStateData getMix method and perform custom logic to return a mix time for any animation pair.