How to detect when most of the snapshot is transparent?

I’m using code similar to the sample code SnapshotEraser to create kind of scratch card activity for kids.

When most of the snapshot canvas is cleared I’d like to show the complete back image. But could not find any means to query the canvas.

Is there a way to detect how much of the canvas is transparent and on lets say 10% fill perform some action?

Hi @rune7,

There’s not a way to internally detect transparency, but I think you could achieve this basic behavior in a different manner: create a separate large “grid” of squares (vector rectangles) which are transparent but hit-sensitive (.isHitTestable) and overlay the entire image with enough of these squares to cover it entirely. Basically, imagine it like an invisible piece of graph paper overlaying the image. Then, as the user erases over the image, use separate functionality to detect where the touch is and, as the user touches/drags over these invisible squares, remove them and count how many have been removed in total. Based on the total number of squares and the number that have been removed, do the math and figure out when a certain percentage has been cleared. When that occurs, you know that the drawing has been sufficiently “cleared”.

Hope this helps,

Brent

Hi Brent,

Thanks. I’ve implemented something similar (but without the need to actually create the grid graphics objects). I guess I was hoping for an Easter egg :) 

Adi

Hi @rune7,

There’s not a way to internally detect transparency, but I think you could achieve this basic behavior in a different manner: create a separate large “grid” of squares (vector rectangles) which are transparent but hit-sensitive (.isHitTestable) and overlay the entire image with enough of these squares to cover it entirely. Basically, imagine it like an invisible piece of graph paper overlaying the image. Then, as the user erases over the image, use separate functionality to detect where the touch is and, as the user touches/drags over these invisible squares, remove them and count how many have been removed in total. Based on the total number of squares and the number that have been removed, do the math and figure out when a certain percentage has been cleared. When that occurs, you know that the drawing has been sufficiently “cleared”.

Hope this helps,

Brent

Hi Brent,

Thanks. I’ve implemented something similar (but without the need to actually create the grid graphics objects). I guess I was hoping for an Easter egg :) 

Adi