Reputation: 1107
What's the "right" way to expand the hover area of a certain component? In other words, how do I turn a component's state to hovered when my mouse pointer is closer than a certain distance X? I can think of a bunch of ways to do this, but they all seem hacks and I'm curious if anyone has strong feelings about a better designed way to do something like this.
And since we're at it, how would you make alpha of the component proportional to the mouse cursor distance from the component, so that the component fades in as we approach it? Again I can think of various hacks, but not sure what a clean approach would be.
thank you!
f
Upvotes: 1
Views: 156
Reputation: 2660
I would suggest centering the component inside a Canvas that is sized to pad the target component by the desired amount. You can then listen to the Canvas for mouseover and trigger your logic to enable hover. That seems to be the cleanest approach to me -- alternately you could listen for mousemove on the Stage and constantly check the mouse distance to the target component... but that seems messy.
As for alpha I would take a similar approach. Let the outer edge of the alpha container represent the minimum alpha and the inner edge represent the maximum alpha. How you scale in between (linear, etc..) is up to you.
Upvotes: 1