OSDN Git Service

[added] Forever Action to repeat other actions indefinetly.
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 23 Oct 2010 21:13:39 +0000 (21:13 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 23 Oct 2010 21:13:39 +0000 (21:13 +0000)
[changed] All actions to be useable with forever. This means reseting done/taken in setTarget.

gdx/src/com/badlogic/gdx/scenes/scene2d/actions/Delay.java
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/FadeIn.java
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/FadeOut.java
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/Forever.java [new file with mode: 0644]
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/MoveTo.java
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/RotateTo.java
gdx/src/com/badlogic/gdx/scenes/scene2d/actions/ScaleTo.java

index 4e86597..b4a5917 100644 (file)
@@ -23,7 +23,6 @@ public class Delay implements Action
        public static Delay $( Action action, float duration )\r
        {\r
                Delay delay = pool.newObject();\r
-               delay.taken = 0;\r
                delay.duration = duration;\r
                delay.action = action;\r
                return delay;\r
@@ -33,6 +32,7 @@ public class Delay implements Action
        public void setTarget(Actor actor) \r
        {\r
                action.setTarget( actor );\r
+               this.taken = 0;\r
        }\r
 \r
        @Override\r
index b1e2025..7336de2 100644 (file)
@@ -28,8 +28,6 @@ public class FadeIn implements Action
                FadeIn action = pool.newObject();\r
                action.duration = duration;\r
                action.invDuration = 1 / duration;\r
-               action.taken = 0;\r
-               action.done = false;\r
                return action;\r
        }\r
 \r
@@ -40,6 +38,8 @@ public class FadeIn implements Action
                this.target.color.a = 0;\r
                this.startAlpha = 0;\r
                this.deltaAlpha = 1;\r
+               this.taken = 0;\r
+               this.done = false;\r
        }\r
 \r
        @Override\r
index 5706657..c74b4b3 100644 (file)
@@ -28,8 +28,6 @@ public class FadeOut implements Action
                FadeOut action = pool.newObject();\r
                action.duration = duration;\r
                action.invDuration = 1 / duration;\r
-               action.taken = 0;\r
-               action.done = false;\r
                return action;\r
        }\r
 \r
@@ -40,6 +38,8 @@ public class FadeOut implements Action
                this.target.color.a = 1;\r
                this.startAlpha = 1;\r
                this.deltaAlpha = -1;\r
+               this.taken = 0;\r
+               this.done = false;\r
        }\r
 \r
        @Override\r
diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/actions/Forever.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/actions/Forever.java
new file mode 100644 (file)
index 0000000..68b16a6
--- /dev/null
@@ -0,0 +1,48 @@
+package com.badlogic.gdx.scenes.scene2d.actions;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Action;\r
+import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.utils.Pool;\r
+import com.badlogic.gdx.utils.Pool.PoolObjectFactory;\r
+\r
+public class Forever implements Action \r
+{\r
+       static final Pool<Forever> pool = new Pool<Forever>( new PoolObjectFactory<Forever>() {\r
+               @Override\r
+               public Forever createObject() \r
+               {\r
+                       return new Forever( );\r
+               }\r
+       }, 100 );\r
+       \r
+       private Action action;\r
+       private Actor target;\r
+       \r
+       public static Forever $( Action action )\r
+       {\r
+               Forever forever = pool.newObject();\r
+               forever.action = action;\r
+               return forever;\r
+       }\r
+\r
+       @Override\r
+       public void setTarget(Actor actor) \r
+       {\r
+               this.target = actor;\r
+               action.setTarget( actor );\r
+       }\r
+\r
+       @Override\r
+       public void act(float delta) \r
+       {\r
+               action.act( delta );\r
+               if( action.isDone() )\r
+                       action.setTarget( target );\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isDone() {\r
+               return false;\r
+       }\r
+}\r
index d02dbba..ef7d859 100644 (file)
@@ -36,8 +36,6 @@ public class MoveTo implements Action
                action.y = y;\r
                action.duration = duration;\r
                action.invDuration = 1 / duration;\r
-               action.taken = 0;\r
-               action.done = false;\r
                return action;\r
        }\r
        \r
@@ -52,6 +50,8 @@ public class MoveTo implements Action
                this.startY = target.y;\r
                this.deltaX = x - target.x;\r
                this.deltaY = y - target.y;\r
+               this.taken = 0;\r
+               this.done = false;\r
        }\r
 \r
        @Override\r
index db553c6..21bbd71 100644 (file)
@@ -30,8 +30,6 @@ public class RotateTo implements Action
                action.rotation = rotation;\r
                action.duration = duration;\r
                action.invDuration = 1 / duration;\r
-               action.taken = 0;\r
-               action.done = false;\r
                return action;\r
        }\r
        \r
@@ -41,6 +39,8 @@ public class RotateTo implements Action
                this.target = actor;\r
                this.startRotation = target.rotation;\r
                this.deltaRotation = rotation - target.rotation;\r
+               this.taken = 0;\r
+               this.done = false;\r
        }\r
 \r
        @Override\r
index 7e1a25a..0d0b085 100644 (file)
@@ -34,8 +34,6 @@ public class ScaleTo implements Action
                action.scaleY = scaleY;\r
                action.duration = duration;\r
                action.invDuration = 1 / duration;\r
-               action.taken = 0;\r
-               action.done = false;\r
                return action;\r
        }\r
        \r
@@ -47,6 +45,8 @@ public class ScaleTo implements Action
                this.deltaScaleX= scaleX - target.scaleX;\r
                this.startScaleY = target.scaleY;\r
                this.deltaScaleY= scaleY - target.scaleY;\r
+               this.taken = 0;\r
+               this.done = false;\r
        }\r
 \r
        @Override\r