Hi,
I have imported a PNG image with transparency in my Hype document.
What would be the most straightforward way to detect a click on its non-transparent area? (without creating svg path or vector object).
Thanks.
Not easy, but a fun challenge!
It requires setting a class on the image: clickable-transparency
It looks at alpha on each pixel and turns on or off click/touch events.
Demo: https://short-umbrella.surge.sh/alpha_detector/alpha_detector.html
alpha_detector.hype.zip (107.2 KB)
With help from GPT-4.1.
2 Likes
Thanks a lot Daniel, it works perfectly!
Do you think there is a way to make it work when 2 PNGs are on top of each other or overlap? (see attachment)
Currently, it prevents clicking on the background PNG while the cursor is still over the foreground PNG's transparent area.
alpha_detector_2PNGs.hype.zip (127.9 KB)
Here's an update: alpha_detector_multiple.hype.zip (127.0 KB)
2 Likes
Thanks a lot Daniel!
This is exactly what I was looking for.