List of usage examples for com.badlogic.gdx.scenes.scene2d Group getChildren
public SnapshotArray<Actor> getChildren()
From source file:com.netthreads.libgdx.scene.SceneHelper.java
License:Apache License
/** * Find hit class.//from w w w. java 2 s . c o m * * @param x Current x position. * @param y Current y position * @param group The starting Group. * @param targetClass The target class type. * @return The target or null if not found. */ @SuppressWarnings("rawtypes") public static Actor hit(float x, float y, Group group, Class targetClass) { SnapshotArray<Actor> children = group.getChildren(); Actor hit = null; boolean found = false; int index = children.size - 1; while (!found && index >= 0) { Actor child = children.get(index); if (child.getClass().isAssignableFrom(targetClass)) { point.x = x; point.y = y; group.localToDescendantCoordinates(child, point); if (child.hit(point.x, point.y, true) != null) { found = true; hit = child; } else if (child instanceof Group) { child = hit(x, y, (Group) child, targetClass); } } index--; } return hit; }
From source file:com.netthreads.libgdx.scene.SceneHelper.java
License:Apache License
/** * Look for intersection between two actors. * <p/>/* ww w .java 2 s . c o m*/ * I have defined this here as I can't extend the base classes Actor and Group. * * @param x The x pos rectangle. * @param y The y pos rectangle. * @param width The rectangle width. * @param height The rectangle height. * @param group The group. * @param targetClass The target class. * @return Target class, null if no intersection. */ @SuppressWarnings("rawtypes") public static Actor intersects(float x, float y, float width, float height, Group group, Class targetClass) { SnapshotArray<Actor> children = group.getChildren(); Actor hit = null; int index = children.size - 1; while (hit == null && index >= 0) { Actor child = children.get(index); point.x = x; point.y = y; group.localToDescendantCoordinates(child, point); // If child is our target class then immediately check for // intersection if (child.getClass().equals(targetClass)) { if (isIntersect(point.x, point.y, width, height, 0, 0, child.getWidth(), child.getHeight())) { hit = child; } } else if (child instanceof Group) { hit = intersects(point.x, point.y, width, height, (Group) child, targetClass); } index--; } return hit; }
From source file:com.netthreads.libgdx.scene.SceneHelper.java
License:Apache License
/** * Look for target hit of specified class. * * @param x Current x position. * @param y Current y position * @param stage The starting stage. * @param targetClass The target class type. * @return Target class or null if not found. */// w w w . ja v a2 s . co m @SuppressWarnings("rawtypes") public static Actor hit(float x, float y, Stage stage, Class targetClass) { Group root = stage.getRoot(); SnapshotArray<Actor> children = root.getChildren(); Actor hit = null; boolean found = false; int index = children.size - 1; while (!found && index >= 0) { Actor child = children.get(index); point.x = x; point.y = y; root.localToDescendantCoordinates(child, point); Actor childHit = root.hit(point.x, point.y, true); if (childHit != null && childHit.getClass().isAssignableFrom(targetClass)) { found = true; hit = childHit; } else { index--; } } return hit; }
From source file:com.quadbits.gdxhelper.LWPStage.java
License:Apache License
private void disposeActors(Group group) { for (Actor actor : group.getChildren()) { if (actor instanceof Group) { disposeActors((Group) actor); } else if (actor instanceof Disposable) { ((Disposable) actor).dispose(); }/* w ww . j a va 2s.c o m*/ } }
From source file:com.quadbits.gdxhelper.screens.LWPScreen.java
License:Apache License
private long getMaxSleepTimeFromGroup(Group group) { long maxSleepTimeMillis = Long.MAX_VALUE; for (Actor actor : group.getChildren()) { if (!(actor instanceof NonContinuousRendering || actor instanceof Group)) { continue; }// ww w. j a va2s . co m long actorMaxSleepTime; if (actor instanceof Group) { actorMaxSleepTime = getMaxSleepTimeFromGroup((Group) actor); } else { actorMaxSleepTime = ((NonContinuousRendering) actor).getMaxSleepTime(); } if (actorMaxSleepTime < maxSleepTimeMillis) { maxSleepTimeMillis = actorMaxSleepTime; } } return maxSleepTimeMillis; }
From source file:com.ridiculousRPG.ui.ActorFocusUtil.java
License:Apache License
public static boolean focusFirstChild(Group actorGrp, Stage stage) { Array<Actor> allActors = actorGrp.getChildren(); for (int i = 0, len = allActors.size; i < len; i++) { Actor a = allActors.get(i);/*from w w w. ja v a 2 s. c om*/ if (isFocusable(a)) return focus(a, false, stage); if (a instanceof Group && focusFirstChild((Group) a, stage)) return true; } return false; }
From source file:com.ridiculousRPG.ui.ActorFocusUtil.java
License:Apache License
public static boolean focusLastChild(Group actorGrp, Stage stage) { Array<Actor> allActors = actorGrp.getChildren(); for (int i = allActors.size - 1; i > -1; i--) { Actor a = allActors.get(i);/*from ww w .ja va 2 s. c o m*/ if (isFocusable(a)) return focus(a, true, stage); if (a instanceof Group && focusLastChild((Group) a, stage)) return true; } return false; }
From source file:es.eucm.ead.editor.control.MokapViews.java
License:Open Source License
protected boolean hideChildIfNeeded(Group parent) { SnapshotArray<Actor> children = parent.getChildren(); for (int i = children.size - 1; i >= 0; --i) { Actor child = children.get(i);/*w ww. ja v a2s . c om*/ if (child instanceof Group) { if (hideChildIfNeeded((Group) child)) { return true; } else if (child instanceof BackListener) { return ((BackListener) child).onBackPressed(); } } } return false; }
From source file:es.eucm.ead.editor.view.builders.scene.groupeditor.GroupEditor.java
License:Open Source License
/** * Ungroups the given group in a list of actors. The resulting actors * accumulates the transformation of the group to keep its absolute * coordinates the same. The group is removed. *///from w w w . jav a 2 s . com private Array<Actor> ungroup(Group group) { Group parent = group.getParent(); Array<Actor> actors = new Array<Actor>(); for (Actor actor : group.getChildren()) { EngineUtils.computeTransformFor(actor, parent); actors.add(actor); } for (Actor actor : actors) { parent.addActor(actor); } group.remove(); fireUngroup(parent, group, actors); boolean multipleSelection = isMultipleSelection(); setMultipleSelection(true); for (Actor a : actors) { addToSelection(a); } fireSelection(); setMultipleSelection(multipleSelection); return actors; }
From source file:es.eucm.ead.editor.view.builders.scene.groupeditor.GroupEditor.java
License:Open Source License
/** * Changes the current edited group to the given one. * // ww w . ja v a 2 s . c om * @param group * must be a direct child of the current edited group. If not, * nothing happens */ public void enterGroupEdition(Group group) { if (group != editedGroup && group != null && group.getChildren().size > 1 && editedGroup.getChildren().contains(group, true)) { editedGroup = group; for (Actor actor : editedGroup.getParent().getChildren()) { // Make non-edited actors transparent if (actor != editedGroup) { Color c = actor.getColor(); actor.setColor(c.r, c.g, c.b, c.a * ALPHA_FACTOR); } } for (Actor actor : editedGroup.getChildren()) { EngineUtils.computeTransformFor(actor, editedGroup.getParent()); } editedGroup.setPosition(0, 0); editedGroup.setRotation(0); editedGroup.setScale(1.0f, 1.0f); clearSelection(); fireSelection(); fireEnteredGroupEdition(editedGroup); } }