How to set a list of clickable shapes
I wouldlike to create small games with Zdog, so I need to be able to click on each shape individually.
I solved the problem with an old technique which is working pretty weel with Zdog : I created 2 canvas, one for the demo and a second I named "ghost" and which is a copy of the first. But not an exact copy because each shape has a unique color which is stored in a catalog of colors. When I click on the "demo" canvas, I store the coordinates of the mouse and I check which color has those coordinates on the "ghost canvas". So I know which shape is clicked.
You can see an example on that pen :
https://codepen.io/gregja/pen/rEGmGB
and I added the code in my repository : https://github.com/gregja/zdogXperiments
It's experimental, but it's a good beginning : don't hesitate to suggest some improvements, all ideas are welcome.
Be careful : don't use anything else than the "getMousePos" function I wrote in the script. I tested different versions and it's the only one which works well with Chrome.
Source: metafizzy/zdog