OSDN Git Service

[added] Group.addActorAt/addActorBefore/addActorAfter
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 7 Jan 2011 06:10:06 +0000 (06:10 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 7 Jan 2011 06:10:06 +0000 (06:10 +0000)
gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java

index 1c28091..ca7cdc4 100644 (file)
@@ -313,8 +313,49 @@ public class Group extends Actor {
                namesToActors.put(actor.name, actor);\r
                actor.parent = this;\r
        }\r
+       \r
+       /**\r
+        * Adds an {@link Actor} at the given index in the group. The first Actor added will be at\r
+        * index 0 and so on. Throws an IndexOutOfBoundsException in case the index is invalid.\r
+        * @param index the index to add the actor at.\r
+        */\r
+       public void addActorAt(int index, Actor actor) {\r
+               children.add(index, actor);\r
+               if(actor instanceof Group)groups.add((Group)actor);\r
+               namesToActors.put(actor.name, actor);\r
+               actor.parent = this;            \r
+       }\r
+       \r
+       /**\r
+        * Adds an {@link Actor} before the given Actor. \r
+        * @param actorBefore the Actor to add the other actor in front of\r
+        * @param actor the Actor to add\r
+        */\r
+       public void addActorBefore(Actor actorBefore, Actor actor) {\r
+               int index = children.indexOf(actorBefore);              \r
+               children.add(index, actor);\r
+               if(actor instanceof Group)groups.add((Group)actor);\r
+               namesToActors.put(actor.name, actor);\r
+               actor.parent = this;            \r
+       }\r
 \r
        /**\r
+        * Adds an {@link Actor} after the given Actor. \r
+        * @param actorAfter the Actor to add the other Actor behind\r
+        * @param actor the Actor to add\r
+        */\r
+       public void addActorAfter(Actor actorAfter, Actor actor) {\r
+               int index = children.indexOf(actorAfter);\r
+               if(index == children.size())                    \r
+                       children.add(actor);\r
+               else\r
+                       children.add(index+1, actor);\r
+               if(actor instanceof Group)groups.add((Group)actor);\r
+               namesToActors.put(actor.name, actor);\r
+               actor.parent = this;            \r
+       }\r
+       \r
+       /**\r
         * Removes an {@link Actor} from this Group.\r
         * @param actor\r
         */\r