In web game I wanted to simulate clicks with coordinates. Game interface using canvas
I tried several things, but nothing help.
I tried to make new MouseEvent but it returns me "true" and nothing happened.
const e1 = new MouseEvent("click", {
clientX: 1673,
clientY: 866
});
canvas.dispatchEvent(e1)
And this returns me error: canvas.elementFromPoint is not a function
canvas.elementFromPoint(1673,866);
What im doing wrong or canvas may have another methods to simulate clicks?
The purpose of the
.elementFromPoint()method is to return a HTML element e.g. a<div>. As such this method is chained to the Document object. That means you can't call it on an instance of a canvas element as it simply ain't available there - thus the error message: canvas.elementFromPoint is not a functionHere's an example: