Search code examples
libgdxonclicklistener

hierarchical actors in libgdx. howto design


I have an actor (main), which has itself a list of actors (childs). In the draw() method of the main actor I loop through the list of the child actors and I call the child-actor's draw method, which workd fine.

in my childs actor I have added an InputListener for touch events. When adding that child seperatly to the stage, the event is fired. -> ok.

But when I add the main actor to the stage, the events of the child actors are not fired. (Because they are not known to the stage I think)

How to design this hirarchical situation with my actors, so the events of my childs are fired ?

Do I need to add all childs to the stage ?


Solution

  • Check the Group class. It does exactly what you want to achieve, so either use it or inherit from it. If both is not possible, look how it is implemented there. :-)