# Mouse position is incorect on pointerdown

**URL:** https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383
**Category:** Phaser 3
**Created:** [April 24, 2021, 7:28pm UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383 "2021-04-24T19:28:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://phaser.discourse.group/u/Take)
#### Post date: [April 24, 2021, 7:28pm UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/1 "2021-04-24T19:28:29Z")

</div>

Hi, im trying to make to add object on click, but i have a problem when game is scaled, the position is incorrect.

Im using this for a game scale

mode: Phaser.Scale.FIT,  
autoCenter: Phaser.Scale.CENTER\_BOTH

and this to get the position of the mouse

this.scene.input.on(‘pointerdown’,function(pointer){

```
        var pointX = pointer.x;

        var pointY = pointer.y;
         
        App.graphics.strokeRectShape(new Phaser.Geom.Rectangle(pointX, pointY, 32, 32));

    });

```

But the position is wrong, everytime when you change browser size and game scale is changed mouse position is wrong and rect is drawn on wrong position.

Also when you move camera, position is also wrong.

It there any trick to fix this? Thanks.

---

<div class="post-metadata">

### Author: ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)
#### Post date: [April 25, 2021, 7:27am UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/2 "2021-04-25T07:27:36Z")

</div>

Seems to work fine for me (3.54.0).  
When using camera you probably need to use pointer.worldX.

---

<div class="post-metadata">

### Author: ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://phaser.discourse.group/u/Take)
#### Post date: [April 25, 2021, 8:01am UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/3 "2021-04-25T08:01:43Z")

</div>

Thank you, i did like this and its working

var pointX = this.scene.input.mousePointer.x + this.scene.cameras.main.\_scrollX;  
var pointY = this.scene.input.mousePointer.y + this.scene.cameras.main.\_scrollY;

but i also tried your solution and its working also!!!

var pointX = this.scene.input.mousePointer.worldX;  
var pointY = this.scene.input.mousePointer.worldY;

Thank you, i will use worldX/Y its less code. Im using phaser (v3.53.1)

---

<div class="post-metadata">

### Author: ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://phaser.discourse.group/u/Take)
#### Post date: [April 25, 2021, 8:20am UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/4 "2021-04-25T08:20:14Z")

</div>

Hm I updated now to phaser (v3.54.0) and pointerdown doesnt work at all.  
Im using DOM for game ui and phaser place div above canvas and that is blocking mouse click.  
I tried setTopOnly but its not working. When i move canvas above div, everything is working fine.

However phaser (v3.53.1) didnt have this problem.

---

<div class="post-metadata">

### Author: ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)
#### Post date: [April 25, 2021, 8:26am UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/5 "2021-04-25T08:26:50Z")

</div>

Yeah, known bug. Fixed in 55.  
For now you could do:

> [@DOM Container blocks pointer events](https://phaser.discourse.group/t/dom-container-blocks-pointer-events/9261/7):
>
> new Phaser.Game({ callbacks: { postBoot: function (game) { game.domContainer.style.pointerEvents = 'none'; }, }, }); But you will need to set pointer-events: auto on any HTML elements you want clickable.

---

<div class="post-metadata">

### Author: ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://phaser.discourse.group/u/Take)
#### Post date: [April 25, 2021, 8:32am UTC](https://phaser.discourse.group/t/mouse-position-is-incorect-on-pointerdown/9383/6 "2021-04-25T08:32:59Z")

</div>

Nice, now its working, its a good that there is the solution. Thanks
