corona icon indicating copy to clipboard operation
corona copied to clipboard

Hit-test-only masks

Open ggcrunchy opened this issue 1 year ago • 0 comments

Basically, this is for the case where you want the hit-testing feature of masks, but don't need their graphical effect. This avoids their VRAM cost, as well as batch-breaking that results from the change in mask texture.

Furthermore, if your display object uses a bitmap you can have it sample that directly, and never load an actual mask asset.

On at least some platforms, there are performance costs when computing a loaded mask's grayscale values (future PR), but of course if you skip the load altogether you'll only pay for the bitmap, which you're already doing.

This came up while @mark-sgs and I were testing some stuff on the experimental build—since it flushed out some performance issues at scale—although this PR is independent of said build.

--

This adds two new functions:

mask = graphics.newHitTestOnlyMask( filename[, baseDir] ) mask = graphics.newHitTestOnlyMaskFromPaint( [opts] )

The first one loads from a file as usual, but has no GPU presence. The latter will pick up the display object's image or bitmap paint instead.

At the moment there are no actual opts. I thought small non-0 alphas might be a problem, so this was available for threshold tuning, but so far that hasn't been an issue.

Support for image sheets would be an obvious future improvement / need, but bitmaps are already useful.

--

Here's my test:

test mask thing.zip

You can set TestMaskFromPaint to true to do a bitmap-based test, else use a mask file.

In the former case the background will blink if you touch it and not the little image. In either test you'll get a printout of the touch phase when clicking on the image.

ggcrunchy avatar Apr 02 '23 00:04 ggcrunchy