metafizzy / metafizzy/zdog

How to set a list of clickable shapes

Open
#75 19 comments 9 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
10.7k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the issue's CodePen example and the linked zdogXperiments repository, focusing on the getMousePos function and the separate demo and ghost canvases. Determine whether Zdog should support per-shape click handling directly and define what a supported, documented solution would look like.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.