> I never imagined something so simple would be so complicated.
I've been using Construct for many years, and this is probably the first time I've seen someone ask this. In 99.99% of cases, people want to scale the game while preserving the aspect ratio.
Anyway, here's a simple way to recalculate the mouse position:
> function OnPointerMove(e, runtime)
{
const w = window.innerWidth;
const h = window.innerHeight;
const layerX = e.clientX * (1920/w);
const layerY = e.clientY * (1080/h);
const sprite = runtime.objects.Sprite.getFirstInstance();
sprite.x = layerX;
sprite.y = layerY;
}
Thank you for the code example, but I'm struggling to understand how to use it correctly.
I've been trying to implement it with help from GPT and Claude AI, but neither of them can figure out how to make it work. Everything they suggest based on your code doesn't fix the input coordinates.
I'm using CSS to stretch the canvas:
javascriptcanvas.style.width = "100vw";
canvas.style.height = "100vh";
And I tried using your coordinate conversion:
javascriptconst layerX = e.clientX * (1920 / w);
const layerY = e.clientY * (1080 / h);
But the clicks still don't register in the correct positions on objects.
Could you please provide a more complete example showing:
How to intercept the pointer events before Construct processes them
How to apply the corrected coordinates so Construct's "Mouse → On object clicked" conditions work properly
Or is there a different approach I should be using?
Thanks!