Search code examples
javalibgdxscene2d

LibGDX - Return all actors at a specific stage coordinate


I am trying to find a way to 'review' all actors at a specific stage coordinate, to see if any have a specific identifier (name for example).

The hit method within stage (shown in below code) works well for this, but stops after finding the first actor (which is a problem if multiple actors are overlapped).

@Override
   public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      Vector2 coord = stage.screenToStageCoordinates(new Vector2((float)screenX,(float)screenY));
      Actor hitActor = stage.hit(coord.x,coord.y,false);

      if(hitActor != null)
         Gdx.app.log("HIT",hitActor.getName());

      return true;
   }

Is there any way for the hit method to continue running after finding the first Actor and return results in an array for example (or some other similar method), or would I be better off just looping through all actors and checking if the bounds overlap every time?


Solution

  • I think looping through all the actors and checking if they were hit is the only way because stage.hit() only returns the deepest actor of that touched point.