mouseover circle HTML5 canvas

后端 未结 2 367
花落未央
花落未央 2021-01-06 08:58

I am wondering how to set an area as a semi-complex shape (circle) defined in the canvas so when the user mouse overs the shape, a function will be called.

I do not

相关标签:
2条回答
  • 2021-01-06 09:37

    If you know where the mouse is and you know where the circle is on the canvas then the mouse is inside the circle when the distance from the mouse to the center of the circle is less that the radius. If that's true manually call what ever you need to call.

    Hope that helped

    0 讨论(0)
  • 2021-01-06 09:55

    If you are going to have multiple semi-complex shapes and don't want to have to make any complicated math functions, you can always use a ghost canvas.

    The idea is that when you want to test for a shape, you draw each relevant shape to a canvas in-memory and test the mouse x/y pixel to see if something is there.

    I detail how to do it in this tutorial.

    It works beautifully for smaller amounts of objects, but if you plan on having more than ~200 objects on the screen, you will want to switch to faster, mathematical methods.

    0 讨论(0)
提交回复
热议问题