hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

enableEvents false, causes findActorAtPosition to no longer work #93

Closed MHOOO closed 11 years ago

MHOOO commented 11 years ago

I have an ActorContainer that contains several fields (i.e. actors) and I wanted to colorize those fields when the mouse was dragged over the ActorContainer. So in order to get events on the ActorContainer, I disabled events on the Actors that are inside it. Now however, I am no longer able to get any child using the ActorContainer.findActorAtPosition function. Is this intended behavior?

hyperandroid commented 11 years ago

Yes, this is the expected behavior. Any suggestion ?

robboerman commented 11 years ago

Just put an invisible "proxy" actor the same size as the actorcontainer as the last child in actorcontainer. Catch the mouse events on that proxy actor and call findActorAtPosition with the coordinates on the container. That should work.

MHOOO commented 11 years ago

Thanks for the tip, but I basically worked around the issue by handling the events on the individual childs contained within the ActorContainer. I find the behavior to be strange however, since the function name and documentation does not hint at this behavior at all.

Here's another problem with findActorAtPosition: if I scale down the ActorContainer (setScale(.5,.5)), then findActorAtPosition no longer returns the correct result. Is this intended behavior as well?

MHOOO commented 11 years ago

Ah, I see. findActorAtPosition requires the parameter to be in view space. I however, passed in the point in model space (i.e. a point relative to the ActorContainers origin). I find that behavior to be unintuitive as well.

hyperandroid commented 11 years ago

You have the following API in an actor:

modelToView, to turn actor's local coordinates into world coordinates. viewToModel, which does the opposite: take an screen coord, and know what local coordinate is. modelToModel, to transform a local coordinate into another actor's space local coordinate.

findActorAtPosition relies on viewToModel, but you can choose what function to use. One thing is that you must never call these functions during animation phase. they are safe to be called from paint code though.

What rob suggest is a very valid option, and then use whatever the coordinate system transformation best fits your need.

Regards,

MHOOO commented 11 years ago

I am calling those functions during the onClick handler - is that valid, or do I have to defer calling them until the paint code?

hyperandroid commented 11 years ago

yes.

MHOOO commented 11 years ago

I'm unsure which of my two questions the "yes" is supposed to answer. The first or the second?

hyperandroid commented 11 years ago

yes. you can call these functions during onclick. best.