@Override public void simpleInitApp() { JmeCanvasContext ctx = (JmeCanvasContext) getContext(); gui = new GUI(this, ctx.getCanvas()); gui.show(); flyCam.setEnabled(false); Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geom.setMaterial(mat); rootNode.attachChild(geom); cinematic = new Cinematic(rootNode, 5); MotionPath path = new MotionPath(); path.addWayPoint(Vector3f.ZERO.clone()); path.addWayPoint(new Vector3f(10, 0, 0)); MotionEvent motionEvent = new MotionEvent(geom, path, 5); cinematic.addCinematicEvent(0, motionEvent); cinematic.fitDuration(); cinematic.setLoopMode(LoopMode.Loop); stateManager.attach(cinematic); }
@Override public void stateChanged(ChangeEvent ce) { JSlider slider = (JSlider) ce.getSource(); float percentage = slider.getValue() / 1000f; float newTime = percentage * cinematic.getDuration(); enqueue(() -> cinematic.setTime(newTime)); }
@Override public void actionPerformed(ActionEvent ae) { Component component = (Component) ae.getSource(); switch (component.getName()) { case "playButton": Runnable runnable; if (cinematic.getPlayState() == PlayState.Playing) { runnable = () -> cinematic.pause(); } else { runnable = () -> cinematic.play(); } enqueue(runnable); break; case "newButton": gui.onNewButtonClick(); break; } }
@Override public void simpleUpdate(float tpf) { if (cinematic.getPlayState() == PlayState.Playing) { valueListener.valueChanged((cinematic.getTime() / cinematic.getDuration()) * 1000f); } }