From 75e82e47f29a97c39801f109464c0ac31d03a6d2 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 20 Jan 2014 08:57:56 +0000 Subject: [PATCH] Fixed an issue in animControl where the onanimCycleDone was called too early. see http://hub.jmonkeyengine.org/forum/topic/onanimcycledone-called-before-animation-completes/#post-257008 git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@10996 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../java/com/jme3/animation/AnimChannel.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/animation/AnimChannel.java b/jme3-core/src/main/java/com/jme3/animation/AnimChannel.java index 7c79bae22..9271add3c 100644 --- a/jme3-core/src/main/java/com/jme3/animation/AnimChannel.java +++ b/jme3-core/src/main/java/com/jme3/animation/AnimChannel.java @@ -31,6 +31,9 @@ */ package com.jme3.animation; +import static com.jme3.animation.LoopMode.Cycle; +import static com.jme3.animation.LoopMode.DontLoop; +import static com.jme3.animation.LoopMode.Loop; import com.jme3.math.FastMath; import com.jme3.util.TempVars; import java.util.BitSet; @@ -59,6 +62,7 @@ public final class AnimChannel { private float time; private float speed; private float timeBlendFrom; + private float blendTime; private float speedBlendFrom; private boolean notified=false; @@ -192,6 +196,11 @@ public final class AnimChannel { */ public void setSpeed(float speed) { this.speed = speed; + if(blendTime>0){ + this.speedBlendFrom = speed; + blendTime = Math.min(blendTime, animation.getLength() / speed); + blendRate = 1/ blendTime; + } } /** @@ -248,7 +257,9 @@ public final class AnimChannel { control.notifyAnimChange(this, name); if (animation != null && blendTime > 0f){ + this.blendTime = blendTime; // activate blending + blendTime = Math.min(blendTime, anim.getLength() / speed); blendFrom = animation; timeBlendFrom = time; speedBlendFrom = speed; @@ -393,8 +404,7 @@ public final class AnimChannel { } animation.setTime(time, blendAmount, control, this, vars); - time += tpf * speed; - + if (animation.getLength() > 0){ if (!notified && (time >= animation.getLength() || time < 0)) { if (loopMode == LoopMode.DontLoop) { @@ -406,7 +416,7 @@ public final class AnimChannel { control.notifyAnimCycleDone(this, animation.getName()); } } - + time += tpf * speed; time = clampWrapTime(time, animation.getLength(), loopMode); if (time < 0){ // Negative time indicates that speed should be inverted