V
V
Vohob Ahmad2020-09-29 15:49:59
JavaScript
Vohob Ahmad, 2020-09-29 15:49:59

Is it possible to know the coordinates of a square inside canvasa?

codepen.io/Mbreti/pen/YzqMoEP When you click inside the canvasa (at any point), the square should move and not teleport under the mouse,
how can I implement it?

as reference
poe.bl.ee/%40%24%26/point

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2020-09-29
@Mbreti

You also have a drawRect() method. All manipulations with Canvas are encapsulated in it. Therefore, inside it, in addition to directly drawing, you can save the coordinates by which the square was drawn the last time.
Then - just refer to these coordinates and use them.
In general, no need to try to find something on the canvas. Think of it simply as a visual representation of the actual state of your application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question