Starling-Framework icon indicating copy to clipboard operation
Starling-Framework copied to clipboard

FeatureRequest: Allow mask touchable to be false - Fix Included

Open IonSwitz opened this issue 9 years ago • 4 comments

Line 295 of DisplayObject.as , in hitTest() if (mMask && !hitTestMask(localPoint)) return null; should probably be changed to if (mMask && mask.touchable && !hitTestMask(localPoint)) return null;

If masks can't be set to "touchable=false", it prevents "scratch ticket" functionality, such as this (rub mouse over hidden shapes):

https://dl.dropboxusercontent.com/u/107200878/MaskCanvasStrokes.html

With the old code, all hit tests always failed, and the demo above doesn't work, as there was no way to detect that the masked out images received touches.

For source code for the demo, update Starling Extension Graphics source tree from GitHub https://github.com/StarlingGraphics/Starling-Extension-Graphics and get the demo code here: http://forum.starling-framework.org/topic/starling-extension-graphics/page/2?replies=34#post-83278

IonSwitz avatar Aug 02 '15 07:08 IonSwitz

Hm ... I see what you mean, and allowing that is indeed useful for such a "scratch ticket" functionality. Without it, you'd need to create an invisible (alpha = 0) copy of the unmasked scratch area and add your touch event listener to that, instead.

However, I don't know if I'd actually grasp this as a developer. When I see that the object never receives any touches because it's masked, would I think about trying to turn "touchable" on the mask off? I'm not so sure.

Do you happen to know how this works in classic Flash?

PrimaryFeather avatar Aug 05 '15 11:08 PrimaryFeather

No, I don't know how this works in classic Flash.

From what I can understand, the alternative would be to add a separate "maskIsTouchable" boolean on the DisplayObject class, but it seems like a waste of a variable :)

If you can think of a more intuitive way to solve this, I'm all ears :)

IonSwitz avatar Aug 05 '15 12:08 IonSwitz

Mhm, I agree, it's questionable if this justifies an additional property. Are there any other opinions on this? Anyone, please feel free to join this discussion! =)

PrimaryFeather avatar Aug 05 '15 14:08 PrimaryFeather

Hi, I think with traditional display list you have an InteractiveObject class, so the inheritance chain is a little bit different.

vpmedia avatar Aug 12 '15 07:08 vpmedia