@@ -29,7 +29,7 @@ public class AnimComposer extends AbstractControl {
2929 private Map <String , Layer > layers = new LinkedHashMap <>();
3030
3131 public AnimComposer () {
32- layers .put (DEFAULT_LAYER , new Layer ());
32+ layers .put (DEFAULT_LAYER , new Layer (this ));
3333 }
3434
3535 /**
@@ -171,7 +171,7 @@ public Action removeAction(String name) {
171171 }
172172
173173 public void makeLayer (String name , AnimationMask mask ) {
174- Layer l = new Layer ();
174+ Layer l = new Layer (this );
175175 l .mask = mask ;
176176 layers .put (name , l );
177177 }
@@ -300,23 +300,30 @@ public void read(JmeImporter im) throws IOException {
300300 super .read (im );
301301 InputCapsule ic = im .getCapsule (this );
302302 animClipMap = (Map <String , AnimClip >) ic .readStringSavableMap ("animClipMap" , new HashMap <String , AnimClip >());
303+ globalSpeed = ic .readFloat ("globalSpeed" , 1f );
303304 }
304305
305306 @ Override
306307 public void write (JmeExporter ex ) throws IOException {
307308 super .write (ex );
308309 OutputCapsule oc = ex .getCapsule (this );
309310 oc .writeStringSavableMap (animClipMap , "animClipMap" , new HashMap <String , AnimClip >());
311+ oc .write (globalSpeed , "globalSpeed" , 1f );
310312 }
311313
312- private class Layer implements JmeCloneable {
314+ private static class Layer implements JmeCloneable {
315+ private AnimComposer ac ;
313316 private Action currentAction ;
314317 private AnimationMask mask ;
315318 private float weight ;
316319 private double time ;
317320
321+ public Layer (AnimComposer ac ) {
322+ this .ac = ac ;
323+ }
324+
318325 public void advance (float tpf ) {
319- time += tpf * currentAction .getSpeed () * globalSpeed ;
326+ time += tpf * currentAction .getSpeed () * ac . globalSpeed ;
320327 // make sure negative time is in [0, length] range
321328 if (time < 0 ) {
322329 double length = currentAction .getLength ();
@@ -337,6 +344,7 @@ public Object jmeClone() {
337344
338345 @ Override
339346 public void cloneFields (Cloner cloner , Object original ) {
347+ ac = cloner .clone (ac );
340348 currentAction = null ;
341349 }
342350 }
0 commit comments