hyperandroid/CAAT — Issue #29: How to make ActorContainer 'transparent' to mouse events
Author: garymcleanhall
Created: 2012-01-21 04:54:41+00:00
State: open

I have fixed a problem I had with your otherwise rather amazing CAAT library.

The problem was that I had two ActorContainers, each with their own ShapeActor children. These were both added to a scene and enableDrag was called on each ShapeActor. Only the last-added ActorContainer's children were responding to mouse events. The reason was that the findActorAtPosition() method would return 'this' if none of the children contained the mouse location. For what I was wanting to achieve, I needed only the ShapeActor children to be returned from this method, and never an ActorContainer.

Long story short, you can make an ActorContainer transparent to mouse events by replacing the final return statement of ActorContainer.findActorAtPosition() with this:

return this.constructor == CAAT.ActorContainer ? null : this;

In other words, "given that the mouse is not contained in one of my children, if I am purely an ActorContainer, admit that I haven't found an actor - otherwise, return this concrete subclass of ActorContainer."