Skip to content

Pointer position incorrect of canvas is rotated #7175

Open

Description

@leemanhopeter

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>

Activity

  1. photonstorm commented on Jun 27, 2025

    @photonstorm
    Collaborator

    We will add this information to the documentation, so thanks for highlighting it - we have no intention of changing our input code to handle this though, as there's no logical reason for ever doing this in practice.

  2. leemanhopeter commented on Jun 29, 2025

    @leemanhopeter
    Author

    The reason we are doing this is that we want to force the orientation of a game to landscape, and allow the game to be in fullscreen mode. So if the player is in portrait mode and the game is in fullscreen, we want to rotate the canvas 90 degrees so that it is in landscape mode, but then the input handling will be incorrect.

    What is the recommended way of doing this?

  3. smshuja commented on Oct 29, 2025

    @smshuja

    @photonstorm We also have the same issue. The game is loaded in a Webview which is locked in portrait mode and we have no control over it.

  4. added a commit that references this issue on Apr 12, 2026
    0625d14
  5. added a commit that references this issue on Jul 21, 2026
    3ee99ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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