/** * used internally to cleanup the cinematic. Called when the clear() method * is called */ @Override public void dispose() { for (CinematicEvent event : cinematicEvents) { event.dispose(); } } }
/** * fits the duration of the cinematic to the duration of all its child * cinematic events */ public void fitDuration() { KeyFrame kf = timeLine.getKeyFrameAtIndex(timeLine.getLastKeyFrameIndex()); float d = 0; for (int i = 0; i < kf.getCinematicEvents().size(); i++) { CinematicEvent ce = kf.getCinematicEvents().get(i); float dur = timeLine.getKeyFrameTime(kf) + ce.getDuration() * ce.getSpeed(); if (d < dur) { d = dur; } } initialDuration = d; }
/** * called internally */ @Override public void onPause() { for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); if (ce.getPlayState() == PlayState.Playing) { ce.pause(); } } }
/** * called internally */ @Override public void onPlay() { if (isInitialized()) { if (playState == PlayState.Paused) { for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); if (ce.getPlayState() == PlayState.Paused) { ce.play(); } } } } }
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);
/** * used internally * * @param stateManager the state manager * @param app the application */ public void initialize(AppStateManager stateManager, Application app) { initEvent(app, this); for (CinematicEvent cinematicEvent : cinematicEvents) { cinematicEvent.initEvent(app, this); } if(!cameras.isEmpty()){ for(CameraNode n : cameras.values()){ n.setCamera(app.getCamera()); } } initialized = true; }
/** * enqueue a cinematic event to a cinematic. This is a handy method when you * want to chain event of a given duration without knowing their initial * duration * * @param cinematicEvent the cinematic event to enqueue * @return the timestamp the event was scheduled. */ public float enqueueCinematicEvent(CinematicEvent cinematicEvent) { float scheduleTime = nextEnqueue; addCinematicEvent(scheduleTime, cinematicEvent); nextEnqueue += cinematicEvent.getInitialDuration(); return scheduleTime; }
/** * used internally, don't call this directly. * * @param tpf */ @Override public void onUpdate(float tpf) { int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //iterate to make sure every key frame is triggered for (int i = lastFetchedKeyFrame + 1; i <= keyFrameIndex; i++) { KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { keyFrame.trigger(); } } for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); ce.internalUpdate(tpf); } lastFetchedKeyFrame = keyFrameIndex; }
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);
/** * called internally */ @Override public void onPause() { for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); if (ce.getPlayState() == PlayState.Playing) { ce.pause(); } } }
/** * called internally */ @Override public void onPlay() { if (isInitialized()) { if (playState == PlayState.Paused) { for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); if (ce.getPlayState() == PlayState.Paused) { ce.play(); } } } } }
/** * Adds a cinematic event to this cinematic at the given timestamp. This * operation returns a keyFrame * * @param timeStamp the time when the event will start after the beginning * of the cinematic * @param cinematicEvent the cinematic event * @return the keyFrame for that event. */ public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); if (keyFrame == null) { keyFrame = new KeyFrame(); timeLine.addKeyFrameAtTime(timeStamp, keyFrame); } keyFrame.cinematicEvents.add(cinematicEvent); cinematicEvents.add(cinematicEvent); if (isInitialized()) { cinematicEvent.initEvent(null, this); } return keyFrame; }
/** * enqueue a cinematic event to a cinematic. This is a handy method when you * want to chain event of a given duration without knowing their initial * duration * * @param cinematicEvent the cinematic event to enqueue * @return the timestamp the event was scheduled. */ public float enqueueCinematicEvent(CinematicEvent cinematicEvent) { float scheduleTime = nextEnqueue; addCinematicEvent(scheduleTime, cinematicEvent); nextEnqueue += cinematicEvent.getInitialDuration(); return scheduleTime; }
/** * used internally, don't call this directly. * * @param tpf */ @Override public void onUpdate(float tpf) { int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //iterate to make sure every key frame is triggered for (int i = lastFetchedKeyFrame + 1; i <= keyFrameIndex; i++) { KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { keyFrame.trigger(); } } for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); ce.internalUpdate(tpf); } lastFetchedKeyFrame = keyFrameIndex; }
/** * removes the first occurrence found of the given cinematicEvent. * * @param cinematicEvent the cinematicEvent to remove * @return true if the element has been removed */ public boolean removeCinematicEvent(CinematicEvent cinematicEvent) { cinematicEvent.dispose(); cinematicEvents.remove(cinematicEvent); for (KeyFrame keyFrame : timeLine.values()) { if (keyFrame.cinematicEvents.remove(cinematicEvent)) { return true; } } return false; }
/** * fits the duration of the cinematic to the duration of all its child * cinematic events */ public void fitDuration() { KeyFrame kf = timeLine.getKeyFrameAtIndex(timeLine.getLastKeyFrameIndex()); float d = 0; for (int i = 0; i < kf.getCinematicEvents().size(); i++) { CinematicEvent ce = kf.getCinematicEvents().get(i); float dur = timeLine.getKeyFrameTime(kf) + ce.getDuration() * ce.getSpeed(); if (d < dur) { d = dur; } } initialDuration = d; }
/** * used internally * * @param stateManager the state manager * @param app the application */ public void initialize(AppStateManager stateManager, Application app) { initEvent(app, this); for (CinematicEvent cinematicEvent : cinematicEvents) { cinematicEvent.initEvent(app, this); } if(!cameras.isEmpty()){ for(CameraNode n : cameras.values()){ n.setCamera(app.getCamera()); } } initialized = true; }
/** * removes the first occurrence found of the given cinematicEvent for the * given time stamp. * * @param timeStamp the timestamp when the cinematicEvent has been added * @param cinematicEvent the cinematicEvent to remove * @return true if the element has been removed */ public boolean removeCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { cinematicEvent.dispose(); KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); return removeCinematicEvent(keyFrame, cinematicEvent); }