Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.input.activePointer.worldY or X doesn't get updated when camera is moving #4216

Closed
JOGUI22 opened this issue Dec 5, 2018 · 4 comments
Closed

Comments

@JOGUI22
Copy link

JOGUI22 commented Dec 5, 2018

Version

  • Phaser Version: 3.15.1
  • Operating system: Fedora 27
  • Browser: no specific

Description

Hello, I've been searching for a solution of this problem for some days. I've found it by working on some ideas.

When the camera is set with this.cameras.main.startFollow(...) to something and it moves, the activePointer is not updating his worldX and Y position. It only gets updated when the cursor is moved.

You can easly check this behaviour with this sample code. Just open the inspector and read the console.log() in the console. You'll see how the worldX/Y position doesn't update when the camera is moving, only when the pointer(mouse) moves.

I expected to get thouse worldX/Y values get updated when the camera moves, therefore changing the position the pointer respect to the world coords.

Example Test Code

//Based on: https://labs.phaser.io/edit.html?src=src\camera\follow%20user%20controlled%20sprite.js
var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    physics: {
        default: 'arcade',
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var player;
var cursors;

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('bg', 'assets/pics/the-end-by-iloe-and-made.jpg');
    this.load.image('block', 'assets/sprites/block.png');
}

function create ()
{
    //  Set the camera and physics bounds to be the size of 4x4 bg images
    this.cameras.main.setBounds(0, 0, 1920 * 2, 1080 * 2);
    this.physics.world.setBounds(0, 0, 1920 * 2, 1080 * 2);

    //  Mash 4 images together to create our background
    this.add.image(0, 0, 'bg').setOrigin(0);
    this.add.image(1920, 0, 'bg').setOrigin(0).setFlipX(true);
    this.add.image(0, 1080, 'bg').setOrigin(0).setFlipY(true);
    this.add.image(1920, 1080, 'bg').setOrigin(0).setFlipX(true).setFlipY(true);

    cursors = this.input.keyboard.createCursorKeys();

    player = this.physics.add.image(400, 300, 'block');

    player.setCollideWorldBounds(true);

    this.cameras.main.startFollow(player, true, 0.05, 0.05);
}

function update ()
{
    player.setVelocity(0);

    if (cursors.left.isDown)
    {
        player.setVelocityX(-500);
    }
    else if (cursors.right.isDown)
    {
        player.setVelocityX(500);
    }

    if (cursors.up.isDown)
    {
        player.setVelocityY(-500);
    }
    else if (cursors.down.isDown)
    {
        player.setVelocityY(500);
    }
    console.log(this.input.activePointer.worldY)
}

Additional Information

The issue is seen in the ´console.log()´ of the example code. You can also see the behavior in this gif of my mockup. The cursor point of the green line is not getting updated with the mouse position when the camera is moving.

cameranotrefreshingpointerworldcoords

@samme
Copy link
Contributor

samme commented Dec 6, 2018

I think setPollAlways is for this.

@JOGUI22
Copy link
Author

JOGUI22 commented Dec 6, 2018

@samme Yeah, this is what i was searching. Thank you. I understand this is the intended behavior.

@JOGUI22 JOGUI22 closed this as completed Dec 6, 2018
@simeon-smith
Copy link

This does not work on 3.16.

@samme
Copy link
Contributor

samme commented Apr 17, 2019

#4405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants