Example usage for com.badlogic.gdx.scenes.scene2d Group hit

List of usage examples for com.badlogic.gdx.scenes.scene2d Group hit

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Group hit.

Prototype

public Actor hit(float x, float y, boolean touchable) 

Source Link

Usage

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.
 *///from   w ww .j  ava2  s  .  com
@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;
}