浏览代码

Added removeAction(), removeLayer() and removeCurrentAction() to AnimComposer (#1016)

* Added AnimComposer.removeAction() and AnimComposer.removeLayer()

* Added javadoc for AnimComposer.setCurrentAction()

* Moved removing of current action to a separate method.

* Added javadoc for new methods.
Ali-RS 6 年之前
父节点
当前提交
6679873c9b
共有 1 个文件被更改,包括 43 次插入2 次删除
  1. 43 2
      jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

+ 43 - 2
jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

@@ -67,17 +67,40 @@ public class AnimComposer extends AbstractControl {
     public Action setCurrentAction(String name) {
     public Action setCurrentAction(String name) {
         return setCurrentAction(name, DEFAULT_LAYER);
         return setCurrentAction(name, DEFAULT_LAYER);
     }
     }
-
+    
+    /**
+     * Run an action on specified layer.
+     * 
+     * @param actionName The name of the action to run.
+     * @param layerName The layer on which action should run.
+     * @return The action corresponding to the given name.
+     */
     public Action setCurrentAction(String actionName, String layerName) {
     public Action setCurrentAction(String actionName, String layerName) {
         Layer l = layers.get(layerName);
         Layer l = layers.get(layerName);
         if (l == null) {
         if (l == null) {
             throw new IllegalArgumentException("Unknown layer " + layerName);
             throw new IllegalArgumentException("Unknown layer " + layerName);
         }
         }
+        
         Action currentAction = action(actionName);
         Action currentAction = action(actionName);
         l.time = 0;
         l.time = 0;
         l.currentAction = currentAction;
         l.currentAction = currentAction;
         return currentAction;
         return currentAction;
     }
     }
+    
+    /**
+     * Remove current action on specified layer.
+     *
+     * @param layerName The name of the layer we want to remove it's action.
+     */
+    public void removeCurrentAction(String layerName) {
+        Layer l = layers.get(layerName);
+        if (l == null) {
+            throw new IllegalArgumentException("Unknown layer " + layerName);
+        }
+        
+        l.time = 0;
+        l.currentAction = null;
+    }
 
 
     public Action action(String name) {
     public Action action(String name) {
         Action action = actions.get(name);
         Action action = actions.get(name);
@@ -101,13 +124,31 @@ public class AnimComposer extends AbstractControl {
     public boolean hasAction(String name) {
     public boolean hasAction(String name) {
         return actions.containsKey(name);
         return actions.containsKey(name);
     }
     }
+    
+    /**
+     * Remove specified action.
+     *
+     * @param name The name of the action to remove.
+     * @return The removed action.
+     */
+    public Action removeAction(String name) {
+        return actions.remove(name);
+    }
 
 
-    public void makeLayer(String name, AnimationMask mask){
+    public void makeLayer(String name, AnimationMask mask) {
         Layer l = new Layer();
         Layer l = new Layer();
         l.mask = mask;
         l.mask = mask;
         layers.put(name, l);
         layers.put(name, l);
     }
     }
 
 
+    /**
+     * Remove specified layer. This will stop the current action on this layer.
+     *
+     * @param name The name of the layer to remove.
+     */
+    public void removeLayer(String name) {
+        layers.remove(name);
+    }
 
 
     public BaseAction actionSequence(String name, Tween... tweens) {
     public BaseAction actionSequence(String name, Tween... tweens) {
         BaseAction action = new BaseAction(Tweens.sequence(tweens));
         BaseAction action = new BaseAction(Tweens.sequence(tweens));