Fixed an issue in AnimationTrack when time was skipped out of bounds of the animation

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9245 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 8ab5a211e2
commit 07e96d02eb
  1. 20
      engine/src/core/com/jme3/cinematic/Cinematic.java
  2. 19
      engine/src/core/com/jme3/cinematic/events/AnimationTrack.java

@ -35,10 +35,8 @@ import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.app.state.AppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.TextureKey;
import com.jme3.cinematic.events.AbstractCinematicEvent;
import com.jme3.cinematic.events.CinematicEvent;
import com.jme3.cinematic.events.CinematicEventListener;
import com.jme3.export.*;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
@ -112,6 +110,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
lastFetchedKeyFrame = -1;
for (int i = 0; i < cinematicEvents.size(); i++) {
CinematicEvent ce = cinematicEvents.get(i);
ce.setTime(0);
ce.stop();
}
enableCurrentCam(false);
@ -217,26 +216,27 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
@Override
public void setTime(float time) {
super.setTime(time);
//stopping all events
for (CinematicEvent ce : cinematicEvents) {
ce.stop();
}
onStop();
super.setTime(time);
int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time);
//triggering all the event from start to "time"
//then computing timeOffset for each event
for (KeyFrame keyFrame : timeLine.values()) {
//KeyFrame keyFrame = timeLine.get(timeLine.keySet());
//then computing timeOffset for each event
for (int i = 0; i <= keyFrameIndex; i++) {
KeyFrame keyFrame = timeLine.get(i);
if (keyFrame != null) {
for (CinematicEvent ce : keyFrame.getCinematicEvents()) {
float t = this.time - timeLine.getKeyFrameTime(keyFrame);
if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) {
ce.play();
ce.setTime(t);
}
ce.setTime(t);
}
}
}
lastFetchedKeyFrame = keyFrameIndex;
if (playState != PlayState.Playing) {
pause();
}

@ -108,6 +108,9 @@ public class AnimationTrack extends AbstractCinematicEvent {
@Override
public void setTime(float time) {
super.setTime(time);
if (channel.getAnimationName() == null) {
channel.setAnim(animationName);
}
float t = time;
if (loopMode == loopMode.Loop) {
t = t % channel.getAnimMaxTime();
@ -121,8 +124,18 @@ public class AnimationTrack extends AbstractCinematicEvent {
}
}
channel.setTime(t);
channel.getControl().update(0);
if (t < 0) {
channel.setTime(0);
channel.reset(true);
}
if (t > channel.getAnimMaxTime()) {
channel.setTime(t);
channel.getControl().update(0);
stop();
} else {
channel.setTime(t);
channel.getControl().update(0);
}
}
@Override
@ -133,7 +146,7 @@ public class AnimationTrack extends AbstractCinematicEvent {
channel.setSpeed(speed);
channel.setLoopMode(loopMode);
channel.setTime(time);
}
}
}
@Override

Loading…
Cancel
Save