List of usage examples for com.badlogic.gdx.scenes.scene2d Group localToDescendantCoordinates
public Vector2 localToDescendantCoordinates(Actor descendant, Vector2 localCoords)
From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java
License:Apache License
/** @param vec the coordinates * @param actor the actor in which coordinate system vec is given * @param other the actor into which coordinate system to convert the coordinates to * @throws IllegalArgumentException if the given actors are not in the same hierarchy */ public static void localToOtherCoordinates(Vector2 vec, Actor actor, Actor other) { Group lastParent = lastParent(actor); if (lastParent == null || lastParent != lastParent(other)) throw new IllegalArgumentException(actor + " and " + other + " are not in the same hierarchy"); actor.localToAscendantCoordinates(lastParent, vec); lastParent.localToDescendantCoordinates(other, vec); }
From source file:com.netthreads.libgdx.scene.SceneHelper.java
License:Apache License
/** * Find hit class.//from w ww.ja v a 2 s . c om * * @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/>//w w w .ja v a 2s. 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 ww. ja va 2 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.stercore.code.net.dermetfan.utils.libgdx.scene2d.Scene2DUtils.java
License:Apache License
/** @param pos the coordinates * @param actor the actor in which coordinate system pos is given * @param other the actor into which coordinate system to convert the coordinates to * @return the given position, converted * @throws IllegalArgumentException if the given actors are not in the same hierarchy */ public static Vector2 localToOtherCoordinates(Vector2 pos, Actor actor, Actor other) { Group lastParent = lastParent(actor); if (lastParent == null || lastParent != lastParent(other)) throw new IllegalArgumentException(actor + " and " + other + " are not in the same hierarchy"); actor.localToAscendantCoordinates(lastParent, pos); lastParent.localToDescendantCoordinates(other, pos); return pos;/* www. j a v a2s. c o m*/ }