Skip to content

setPointerCapture causes uncaught error #7185

@Amzd

Description

@Amzd

Version

  • Phaser Version: v3.90.0
  • Operating system: macOS
  • Browser: *

Description

I would like to allow users to drag things around and continue the drag even if the mouse (temporarily) leaves the window. The API for this is setPointerCapture. But when I use this API, Phaser crashes with Uncaught TypeError: can't access property "x", n is null as soon as the mouse leaves the window.

Example Test Code

https://codepen.io/Amzd/pen/WbQjJEQ

The important part of the codepen is:

this.input.on('pointerdown', function(e) {
    document.querySelector("canvas").setPointerCapture(e.pointerId);
})

Additional Information

There is an alternative API called pointerLock which Phaser does support but it gives a popup "example.com has taken control of your pointer. Press Esc to take back control" while setPointerCapture does not, because it only captures until you release the mouse.

https://phaser.io/examples/v3.85.0/input/mouse/view/pointer-lock

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions