phaserjs / phaserjs/phaser

setPointerCapture causes uncaught error

Open
#7,185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

⌨️ Input
Dominant language
JavaScript
Stars
40.3k
Forks
7.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked CodePen and reproduce the error with the setPointerCapture call in the pointerdown handler. Trace Phaser's pointer input handling when the captured pointer leaves the window, then verify that dragging continues without an uncaught error while the pointer remains captured.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.