phaserjs / phaserjs/phaser

Pointer position incorrect of canvas is rotated

Open
#7,175 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Version

  • Phaser Version: 3.80, 4.0.0-rc.4
  • Operating system: Windows 11

Description

If the canvas is rotated, then the pointer positions will be calculated incorrectly. In the example below, the pointer should change to the hand cursor if and only if the pointer is over the green square, but it is not the case here.

Example Test Code

<!DOCTYPE` html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Phaser Game</title>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            background-color: #333;
        }

        #gameHolder {
            position: absolute;
            top: 100px;
            background: red;
            width: 600px;
            height: 500px;
            transform: rotate(90deg);
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/phaser@4.0.0-rc.4/dist/phaser.min.js"></script>
    <script>

    class Example extends Phaser.Scene {
        create () {
            const rect = this.add.rectangle(50, 50, 300, 300, 0x00FF00, 1).setOrigin(0);

            rect.setInteractive({cursor:'pointer'});
            rect.on('pointermove', () => console.log('move'));
        }
    }

    const config = {
        type: Phaser.AUTO,
        parent: 'gameHolder',
        width:500,
        height:400,
        scene: Example
    };

    const game = new Phaser.Game(config);

    </script>
</head>
<body>
    <div id="gameHolder" ></div>
</body>
</html>

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 with the provided HTML example using Phaser 4.0.0-rc.4, the rotated #gameHolder, setInteractive({cursor:'pointer'}), and the pointermove handler. Trace the pointer-position calculation used by the canvas input system. Done means the hand cursor and pointermove behavior occur only when the pointer is over the green square, including when the canvas is rotated.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.