Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.49 KB | None | 0 0
  1. /*******************************************************************************
  2.  * Copyright 2011 See AUTHORS file.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  ******************************************************************************/
  16.  
  17. package com.badlogic.gdx.scenes.scene2d;
  18.  
  19. import com.badlogic.gdx.graphics.g2d.Batch;
  20. import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
  21. import com.badlogic.gdx.math.Matrix3;
  22. import com.badlogic.gdx.math.Matrix4;
  23. import com.badlogic.gdx.math.Rectangle;
  24. import com.badlogic.gdx.math.Vector2;
  25. import com.badlogic.gdx.scenes.scene2d.utils.Cullable;
  26. import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
  27. import com.badlogic.gdx.utils.Array;
  28. import com.badlogic.gdx.utils.SnapshotArray;
  29.  
  30. /** 2D scene graph node that may contain other actors.
  31.  * <p>
  32.  * Actors have a z-order equal to the order they were inserted into the group. Actors inserted later will be drawn on top of
  33.  * actors added earlier. Touch events that hit more than one actor are distributed to topmost actors first.
  34.  * @author mzechner
  35.  * @author Nathan Sweet */
  36. public class Group extends Actor implements Cullable {
  37.     private final SnapshotArray<Actor> children = new SnapshotArray(true, 4, Actor.class);
  38.     private final Matrix3 localTransform = new Matrix3();
  39.     private final Matrix3 worldTransform = new Matrix3();
  40.     private final Matrix4 computedTransform = new Matrix4();
  41.     private final Matrix4 oldTransform = new Matrix4();
  42.     private boolean transform = true;
  43.     private Rectangle cullingArea;
  44.     private final Vector2 point = new Vector2();
  45.  
  46.     public void act (float delta) {
  47.         super.act(delta);
  48.         Actor[] actors = children.begin();
  49.         for (int i = 0, n = children.size; i < n; i++)
  50.             actors[i].act(delta);
  51.         children.end();
  52.     }
  53.  
  54.     /** Draws the group and its children. The default implementation calls {@link #applyTransform(Batch, Matrix4)} if needed, then
  55.      * {@link #drawChildren(Batch, float)}, then {@link #resetTransform(Batch)} if needed. */
  56.     public void draw (Batch batch, float parentAlpha) {
  57.         if (transform) applyTransform(batch, computeTransform());
  58.         drawChildren(batch, parentAlpha);
  59.         if (transform) resetTransform(batch);
  60.     }
  61.  
  62.     /** Draws all children. {@link #applyTransform(Batch, Matrix4)} should be called before and {@link #resetTransform(Batch)} after
  63.      * this method if {@link #setTransform(boolean) transform} is true. If {@link #setTransform(boolean) transform} is false these
  64.      * methods don't need to be called, children positions are temporarily offset by the group position when drawn. This method
  65.      * avoids drawing children completely outside the {@link #setCullingArea(Rectangle) culling area}, if set. */
  66.     protected void drawChildren (Batch batch, float parentAlpha) {
  67.         parentAlpha *= this.color.a;
  68.         SnapshotArray<Actor> children = this.children;
  69.         Actor[] actors = children.begin();
  70.         Rectangle cullingArea = this.cullingArea;
  71.         if (cullingArea != null) {
  72.             // Draw children only if inside culling area.
  73.             float cullLeft = cullingArea.x;
  74.             float cullRight = cullLeft + cullingArea.width;
  75.             float cullBottom = cullingArea.y;
  76.             float cullTop = cullBottom + cullingArea.height;
  77.             if (transform) {
  78.                 for (int i = 0, n = children.size; i < n; i++) {
  79.                     Actor child = actors[i];
  80.                     if (!child.isVisible()) continue;
  81.                     float cx = child.x, cy = child.y;
  82.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom)
  83.                         child.draw(batch, parentAlpha);
  84.                 }
  85.                 batch.flush();
  86.             } else {
  87.                 // No transform for this group, offset each child.
  88.                 float offsetX = x, offsetY = y;
  89.                 x = 0;
  90.                 y = 0;
  91.                 for (int i = 0, n = children.size; i < n; i++) {
  92.                     Actor child = actors[i];
  93.                     if (!child.isVisible()) continue;
  94.                     float cx = child.x, cy = child.y;
  95.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom) {
  96.                         child.x = cx + offsetX;
  97.                         child.y = cy + offsetY;
  98.                         child.draw(batch, parentAlpha);
  99.                         child.x = cx;
  100.                         child.y = cy;
  101.                     }
  102.                 }
  103.                 x = offsetX;
  104.                 y = offsetY;
  105.             }
  106.         } else {
  107.             // No culling, draw all children.
  108.             if (transform) {
  109.                 for (int i = 0, n = children.size; i < n; i++) {
  110.                     Actor child = actors[i];
  111.                     if (!child.isVisible()) continue;
  112.                     child.draw(batch, parentAlpha);
  113.                 }
  114.                 batch.flush();
  115.             } else {
  116.                 // No transform for this group, offset each child.
  117.                 float offsetX = x, offsetY = y;
  118.                 x = 0;
  119.                 y = 0;
  120.                 for (int i = 0, n = children.size; i < n; i++) {
  121.                     Actor child = actors[i];
  122.                     if (!child.isVisible()) continue;
  123.                     float cx = child.x, cy = child.y;
  124.                     child.x = cx + offsetX;
  125.                     child.y = cy + offsetY;
  126.                     child.draw(batch, parentAlpha);
  127.                     child.x = cx;
  128.                     child.y = cy;
  129.                 }
  130.                 x = offsetX;
  131.                 y = offsetY;
  132.             }
  133.         }
  134.         children.end();
  135.     }
  136.  
  137.     /** Draws the group and its children. The default implementation calls {@link #applyTransform(Batch, Matrix4)} if needed, then
  138.      * {@link #drawChildren(Batch, float)}, then {@link #resetTransform(Batch)} if needed. */
  139.     public void draw (ShapeRenderer shapes, float parentAlpha) {
  140.         if (transform) applyTransform(shapes, computeTransform());
  141.         drawChildren(shapes, parentAlpha);
  142.         if (transform) resetTransform(shapes);
  143.     }
  144.  
  145.     /** Draws all children. {@link #applyTransform(Batch, Matrix4)} should be called before and {@link #resetTransform(Batch)} after
  146.      * this method if {@link #setTransform(boolean) transform} is true. If {@link #setTransform(boolean) transform} is false these
  147.      * methods don't need to be called, children positions are temporarily offset by the group position when drawn. This method
  148.      * avoids drawing children completely outside the {@link #setCullingArea(Rectangle) culling area}, if set. */
  149.     protected void drawChildren (ShapeRenderer shapes, float parentAlpha) {
  150.         parentAlpha *= this.color.a;
  151.         SnapshotArray<Actor> children = this.children;
  152.         Actor[] actors = children.begin();
  153.         Rectangle cullingArea = this.cullingArea;
  154.         if (cullingArea != null) {
  155.             // Draw children only if inside culling area.
  156.             float cullLeft = cullingArea.x;
  157.             float cullRight = cullLeft + cullingArea.width;
  158.             float cullBottom = cullingArea.y;
  159.             float cullTop = cullBottom + cullingArea.height;
  160.             if (transform) {
  161.                 for (int i = 0, n = children.size; i < n; i++) {
  162.                     Actor child = actors[i];
  163.                     if (!child.isVisible()) continue;
  164.                     float cx = child.x, cy = child.y;
  165.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom)
  166.                         child.draw(shapes, parentAlpha);
  167.                 }
  168.                 shapes.flush();
  169.             } else {
  170.                 // No transform for this group, offset each child.
  171.                 float offsetX = x, offsetY = y;
  172.                 x = 0;
  173.                 y = 0;
  174.                 for (int i = 0, n = children.size; i < n; i++) {
  175.                     Actor child = actors[i];
  176.                     if (!child.isVisible()) continue;
  177.                     float cx = child.x, cy = child.y;
  178.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom) {
  179.                         child.x = cx + offsetX;
  180.                         child.y = cy + offsetY;
  181.                         child.draw(shapes, parentAlpha);
  182.                         child.x = cx;
  183.                         child.y = cy;
  184.                     }
  185.                 }
  186.                 x = offsetX;
  187.                 y = offsetY;
  188.             }
  189.         } else {
  190.             // No culling, draw all children.
  191.             if (transform) {
  192.                 for (int i = 0, n = children.size; i < n; i++) {
  193.                     Actor child = actors[i];
  194.                     if (!child.isVisible()) continue;
  195.                     child.draw(shapes, parentAlpha);
  196.                 }
  197.                 shapes.flush();
  198.             } else {
  199.                 // No transform for this group, offset each child.
  200.                 float offsetX = x, offsetY = y;
  201.                 x = 0;
  202.                 y = 0;
  203.                 for (int i = 0, n = children.size; i < n; i++) {
  204.                     Actor child = actors[i];
  205.                     if (!child.isVisible()) continue;
  206.                     float cx = child.x, cy = child.y;
  207.                     child.x = cx + offsetX;
  208.                     child.y = cy + offsetY;
  209.                     child.draw(shapes, parentAlpha);
  210.                     child.x = cx;
  211.                     child.y = cy;
  212.                 }
  213.                 x = offsetX;
  214.                 y = offsetY;
  215.             }
  216.         }
  217.         children.end();
  218.     }
  219.  
  220.     public void drawDebug (ShapeRenderer shapes) {
  221.         if (transform) applyTransform(shapes, computeTransform());
  222.         drawDebugChildren(shapes);
  223.         if (transform) resetTransform(shapes);
  224.     }
  225.  
  226.     /** Draws all children. {@link #applyTransform(Batch, Matrix4)} should be called before and {@link #resetTransform(Batch)} after
  227.      * this method if {@link #setTransform(boolean) transform} is true. If {@link #setTransform(boolean) transform} is false these
  228.      * methods don't need to be called, children positions are temporarily offset by the group position when drawn. This method
  229.      * avoids drawing children completely outside the {@link #setCullingArea(Rectangle) culling area}, if set. */
  230.     protected void drawDebugChildren (ShapeRenderer shapes) {
  231.         SnapshotArray<Actor> children = this.children;
  232.         Actor[] actors = children.begin();
  233.         Rectangle cullingArea = this.cullingArea;
  234.         if (cullingArea != null) {
  235.             // Draw children only if inside culling area.
  236.             float cullLeft = cullingArea.x;
  237.             float cullRight = cullLeft + cullingArea.width;
  238.             float cullBottom = cullingArea.y;
  239.             float cullTop = cullBottom + cullingArea.height;
  240.             if (transform) {
  241.                 for (int i = 0, n = children.size; i < n; i++) {
  242.                     Actor child = actors[i];
  243.                     if (!child.isVisible()) continue;
  244.                     float cx = child.x, cy = child.y;
  245.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom)
  246.                         child.drawDebug(shapes);
  247.                 }
  248.                 shapes.flush();
  249.             } else {
  250.                 // No transform for this group, offset each child.
  251.                 float offsetX = x, offsetY = y;
  252.                 x = 0;
  253.                 y = 0;
  254.                 for (int i = 0, n = children.size; i < n; i++) {
  255.                     Actor child = actors[i];
  256.                     if (!child.isVisible()) continue;
  257.                     float cx = child.x, cy = child.y;
  258.                     if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom) {
  259.                         child.x = cx + offsetX;
  260.                         child.y = cy + offsetY;
  261.                         child.drawDebug(shapes);
  262.                         child.x = cx;
  263.                         child.y = cy;
  264.                     }
  265.                 }
  266.                 x = offsetX;
  267.                 y = offsetY;
  268.             }
  269.         } else {
  270.             // No culling, draw all children.
  271.             if (transform) {
  272.                 for (int i = 0, n = children.size; i < n; i++) {
  273.                     Actor child = actors[i];
  274.                     if (!child.isVisible()) continue;
  275.                     child.drawDebug(shapes);
  276.                 }
  277.                 shapes.flush();
  278.             } else {
  279.                 // No transform for this group, offset each child.
  280.                 float offsetX = x, offsetY = y;
  281.                 x = 0;
  282.                 y = 0;
  283.                 for (int i = 0, n = children.size; i < n; i++) {
  284.                     Actor child = actors[i];
  285.                     if (!child.isVisible()) continue;
  286.                     float cx = child.x, cy = child.y;
  287.                     child.x = cx + offsetX;
  288.                     child.y = cy + offsetY;
  289.                     child.drawDebug(shapes);
  290.                     child.x = cx;
  291.                     child.y = cy;
  292.                 }
  293.                 x = offsetX;
  294.                 y = offsetY;
  295.             }
  296.         }
  297.         children.end();
  298.     }
  299.  
  300.     /** Returns the transform for this group's coordinate system. */
  301.     protected Matrix4 computeTransform () {
  302.         Matrix3 worldTransform = this.worldTransform;
  303.         Matrix3 localTransform = this.localTransform;
  304.  
  305.         float originX = this.originX;
  306.         float originY = this.originY;
  307.         float rotation = this.rotation;
  308.         float scaleX = this.scaleX;
  309.         float scaleY = this.scaleY;
  310.  
  311.         if (originX != 0 || originY != 0)
  312.             localTransform.setToTranslation(originX, originY);
  313.         else
  314.             localTransform.idt();
  315.         if (rotation != 0) localTransform.rotate(rotation);
  316.         if (scaleX != 1 || scaleY != 1) localTransform.scale(scaleX, scaleY);
  317.         if (originX != 0 || originY != 0) localTransform.translate(-originX, -originY);
  318.         localTransform.trn(x, y);
  319.  
  320.         // Find the first parent that transforms.
  321.         Group parentGroup = getParent();
  322.         while (parentGroup != null) {
  323.             if (parentGroup.transform) break;
  324.             parentGroup = parentGroup.getParent();
  325.         }
  326.  
  327.         if (parentGroup != null) {
  328.             worldTransform.set(parentGroup.worldTransform);
  329.             worldTransform.mul(localTransform);
  330.         } else {
  331.             worldTransform.set(localTransform);
  332.         }
  333.  
  334.         computedTransform.set(worldTransform);
  335.         return computedTransform;
  336.     }
  337.  
  338.     /** Set the batch's transformation matrix, often with the result of {@link #computeTransform()}. Note this causes the batch to
  339.      * be flushed. {@link #resetTransform(Batch)} will restore the transform to what it was before this call. */
  340.     protected void applyTransform (Batch batch, Matrix4 transform) {
  341.         oldTransform.set(batch.getTransformMatrix());
  342.         batch.setTransformMatrix(transform);
  343.     }
  344.  
  345.     /** Restores the batch transform to what it was before {@link #applyTransform(Batch, Matrix4)}. Note this causes the batch to be
  346.      * flushed. */
  347.     protected void resetTransform (Batch batch) {
  348.         batch.setTransformMatrix(oldTransform);
  349.     }
  350.  
  351.     /** Set the shape renderer transformation matrix, often with the result of {@link #computeTransform()}. Note this causes the
  352.      * shape renderer to be flushed. {@link #resetTransform(ShapeRenderer)} will restore the transform to what it was before this
  353.      * call. */
  354.     protected void applyTransform (ShapeRenderer shapes, Matrix4 transform) {
  355.         oldTransform.set(shapes.getTransformMatrix());
  356.         shapes.setTransformMatrix(transform);
  357.     }
  358.  
  359.     /** Restores the shape renderer transform to what it was before {@link #applyTransform(Batch, Matrix4)}. Note this causes the
  360.      * shape renderer to be flushed. */
  361.     protected void resetTransform (ShapeRenderer shapes) {
  362.         shapes.setTransformMatrix(oldTransform);
  363.     }
  364.  
  365.     /** Children completely outside of this rectangle will not be drawn. This is only valid for use with unrotated and unscaled
  366.      * actors! */
  367.     public void setCullingArea (Rectangle cullingArea) {
  368.         this.cullingArea = cullingArea;
  369.     }
  370.  
  371.     /** Returns the bounds this group will use to clip it's children, or null. The return value of this method is informative only,
  372.      * eg it is used when drawing debug rects. The group still needs to use {@link ScissorStack} to perform clipping. */
  373.     public Rectangle getScissorBounds () {
  374.         return cullingArea;
  375.     }
  376.  
  377.     public Actor hit (float x, float y, boolean touchable) {
  378.         if (touchable && getTouchable() == Touchable.disabled) return null;
  379.         Array<Actor> children = this.children;
  380.         for (int i = children.size - 1; i >= 0; i--) {
  381.             Actor child = children.get(i);
  382.             if (!child.isVisible()) continue;
  383.             child.parentToLocalCoordinates(point.set(x, y));
  384.             Actor hit = child.hit(point.x, point.y, touchable);
  385.             if (hit != null) return hit;
  386.         }
  387.         return super.hit(x, y, touchable);
  388.     }
  389.  
  390.     /** Called when actors are added to or removed from the group. */
  391.     protected void childrenChanged () {
  392.     }
  393.  
  394.     /** Adds an actor as a child of this group. The actor is first removed from its parent group, if any.
  395.      * @see #remove() */
  396.     public void addActor (Actor actor) {
  397.         actor.remove();
  398.         children.add(actor);
  399.         actor.setParent(this);
  400.         actor.setStage(getStage());
  401.         childrenChanged();
  402.     }
  403.  
  404.     /** Adds an actor as a child of this group, at a specific index. The actor is first removed from its parent group, if any.
  405.      * @param index May be greater than the number of children. */
  406.     public void addActorAt (int index, Actor actor) {
  407.         actor.remove();
  408.         if (index >= children.size)
  409.             children.add(actor);
  410.         else
  411.             children.insert(index, actor);
  412.         actor.setParent(this);
  413.         actor.setStage(getStage());
  414.         childrenChanged();
  415.     }
  416.  
  417.     /** Adds an actor as a child of this group, immediately before another child actor. The actor is first removed from its parent
  418.      * group, if any. */
  419.     public void addActorBefore (Actor actorBefore, Actor actor) {
  420.         actor.remove();
  421.         int index = children.indexOf(actorBefore, true);
  422.         children.insert(index, actor);
  423.         actor.setParent(this);
  424.         actor.setStage(getStage());
  425.         childrenChanged();
  426.     }
  427.  
  428.     /** Adds an actor as a child of this group, immediately after another child actor. The actor is first removed from its parent
  429.      * group, if any. */
  430.     public void addActorAfter (Actor actorAfter, Actor actor) {
  431.         actor.remove();
  432.         int index = children.indexOf(actorAfter, true);
  433.         if (index == children.size)
  434.             children.add(actor);
  435.         else
  436.             children.insert(index + 1, actor);
  437.         actor.setParent(this);
  438.         actor.setStage(getStage());
  439.         childrenChanged();
  440.     }
  441.  
  442.     /** Removes an actor from this group. If the actor will not be used again and has actions, they should be
  443.      * {@link Actor#clearActions() cleared} so the actions will be returned to their
  444.      * {@link Action#setPool(com.badlogic.gdx.utils.Pool) pool}, if any. This is not done automatically. */
  445.     public boolean removeActor (Actor actor) {
  446.         if (!children.removeValue(actor, true)) return false;
  447.         Stage stage = getStage();
  448.         if (stage != null) stage.unfocus(actor);
  449.         actor.setParent(null);
  450.         actor.setStage(null);
  451.         childrenChanged();
  452.         return true;
  453.     }
  454.  
  455.     /** Removes all actors from this group. */
  456.     public void clearChildren () {
  457.         Actor[] actors = children.begin();
  458.         for (int i = 0, n = children.size; i < n; i++) {
  459.             Actor child = actors[i];
  460.             child.setStage(null);
  461.             child.setParent(null);
  462.         }
  463.         children.end();
  464.         children.clear();
  465.         childrenChanged();
  466.     }
  467.  
  468.     /** Removes all children, actions, and listeners from this group. */
  469.     public void clear () {
  470.         super.clear();
  471.         clearChildren();
  472.     }
  473.  
  474.     /** Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group. */
  475.     public <T extends Actor> T findActor (String name) {
  476.         Array<Actor> children = this.children;
  477.         for (int i = 0, n = children.size; i < n; i++)
  478.             if (name.equals(children.get(i).getName())) return (T)children.get(i);
  479.         for (int i = 0, n = children.size; i < n; i++) {
  480.             Actor child = children.get(i);
  481.             if (child instanceof Group) {
  482.                 Actor actor = ((Group)child).findActor(name);
  483.                 if (actor != null) return (T)actor;
  484.             }
  485.         }
  486.         return null;
  487.     }
  488.  
  489.     protected void setStage (Stage stage) {
  490.         super.setStage(stage);
  491.         Array<Actor> children = this.children;
  492.         for (int i = 0, n = children.size; i < n; i++)
  493.             children.get(i).setStage(stage);
  494.     }
  495.  
  496.     /** Swaps two actors by index. Returns false if the swap did not occur because the indexes were out of bounds. */
  497.     public boolean swapActor (int first, int second) {
  498.         int maxIndex = children.size;
  499.         if (first < 0 || first >= maxIndex) return false;
  500.         if (second < 0 || second >= maxIndex) return false;
  501.         children.swap(first, second);
  502.         return true;
  503.     }
  504.  
  505.     /** Swaps two actors. Returns false if the swap did not occur because the actors are not children of this group. */
  506.     public boolean swapActor (Actor first, Actor second) {
  507.         int firstIndex = children.indexOf(first, true);
  508.         int secondIndex = children.indexOf(second, true);
  509.         if (firstIndex == -1 || secondIndex == -1) return false;
  510.         children.swap(firstIndex, secondIndex);
  511.         return true;
  512.     }
  513.  
  514.     /** Returns an ordered list of child actors in this group. */
  515.     public SnapshotArray<Actor> getChildren () {
  516.         return children;
  517.     }
  518.  
  519.     public boolean hasChildren () {
  520.         return children.size > 0;
  521.     }
  522.  
  523.     /** When true (the default), the Batch is transformed so children are drawn in their parent's coordinate system. This has a
  524.      * performance impact because {@link Batch#flush()} must be done before and after the transform. If the actors in a group are
  525.      * not rotated or scaled, then the transform for the group can be set to false. In this case, each child's position will be
  526.      * offset by the group's position for drawing, causing the children to appear in the correct location even though the Batch has
  527.      * not been transformed. */
  528.     public void setTransform (boolean transform) {
  529.         this.transform = transform;
  530.     }
  531.  
  532.     public boolean isTransform () {
  533.         return transform;
  534.     }
  535.  
  536.     /** Converts coordinates for this group to those of a descendant actor. The descendant does not need to be a direct child.
  537.      * @throws IllegalArgumentException if the specified actor is not a descendant of this group. */
  538.     public Vector2 localToDescendantCoordinates (Actor descendant, Vector2 localCoords) {
  539.         Group parent = descendant.getParent();
  540.         if (parent == null) throw new IllegalArgumentException("Child is not a descendant: " + descendant);
  541.         // First convert to the actor's parent coordinates.
  542.         if (parent != this) localToDescendantCoordinates(parent, localCoords);
  543.         // Then from each parent down to the descendant.
  544.         descendant.parentToLocalCoordinates(localCoords);
  545.         return localCoords;
  546.     }
  547.  
  548.     /** If true, debug rectangles will be drawn for this actor and, optionally, all children recursively. */
  549.     public void setDebug (boolean enabled, boolean recursively) {
  550.         setDebug(enabled);
  551.         if (recursively) {
  552.             for (Actor child : children) {
  553.                 if (child instanceof Group) {
  554.                     ((Group)child).setDebug(enabled, recursively);
  555.                 } else {
  556.                     child.setDebug(enabled);
  557.                 }
  558.             }
  559.         }
  560.     }
  561.  
  562.     /** Calls {@link #setDebug(boolean, boolean)} with {@code true, true}. */
  563.     public Group debugAll () {
  564.         setDebug(true, true);
  565.         return this;
  566.     }
  567.  
  568.     /** Prints the actor hierarchy recursively for debugging purposes. */
  569.     public void print () {
  570.         print("");
  571.     }
  572.  
  573.     private void print (String indent) {
  574.         Actor[] actors = children.begin();
  575.         for (int i = 0, n = children.size; i < n; i++) {
  576.             System.out.println(indent + actors[i]);
  577.             if (actors[i] instanceof Group) ((Group)actors[i]).print(indent + "|  ");
  578.         }
  579.         children.end();
  580.     }
  581. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement