From: badlogicgames Date: Fri, 7 Jan 2011 06:10:06 +0000 (+0000) Subject: [added] Group.addActorAt/addActorBefore/addActorAfter X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f7c0d0e4aeee90039b2cd792f5e196abef353445;p=mikumikustudio%2Flibgdx-mikumikustudio.git [added] Group.addActorAt/addActorBefore/addActorAfter --- diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java index 1c28091c9..ca7cdc41e 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java @@ -313,8 +313,49 @@ public class Group extends Actor { namesToActors.put(actor.name, actor); actor.parent = this; } + + /** + * Adds an {@link Actor} at the given index in the group. The first Actor added will be at + * index 0 and so on. Throws an IndexOutOfBoundsException in case the index is invalid. + * @param index the index to add the actor at. + */ + public void addActorAt(int index, Actor actor) { + children.add(index, actor); + if(actor instanceof Group)groups.add((Group)actor); + namesToActors.put(actor.name, actor); + actor.parent = this; + } + + /** + * Adds an {@link Actor} before the given Actor. + * @param actorBefore the Actor to add the other actor in front of + * @param actor the Actor to add + */ + public void addActorBefore(Actor actorBefore, Actor actor) { + int index = children.indexOf(actorBefore); + children.add(index, actor); + if(actor instanceof Group)groups.add((Group)actor); + namesToActors.put(actor.name, actor); + actor.parent = this; + } /** + * Adds an {@link Actor} after the given Actor. + * @param actorAfter the Actor to add the other Actor behind + * @param actor the Actor to add + */ + public void addActorAfter(Actor actorAfter, Actor actor) { + int index = children.indexOf(actorAfter); + if(index == children.size()) + children.add(actor); + else + children.add(index+1, actor); + if(actor instanceof Group)groups.add((Group)actor); + namesToActors.put(actor.name, actor); + actor.parent = this; + } + + /** * Removes an {@link Actor} from this Group. * @param actor */