Sign in to follow this  
Kadith

mousePointer.button changes from MIDDLE_BUTTON to LEFT_BUTTON on drag

Recommended Posts

First time posting here so let me know if I've made any mistakes!

I'm currently using Phaser 2.6.2 and am attempting to implement a panning feature using the middle mouse button. I found that when the mouseMove event is called that game.input.mousePointer.button variable is forced to be LEFT_BUTTON.

I've made this small example in Phaser's sandbox. As soon as the cursor enters the stage it thinks LEFT_BUTTON is down. If you hold the middle mouse button down without moving the mouse it will register MIDDLE_BUTTON as being down until the mouse is moved again.

Hopefully it's just something I'm doing wrong but if not is there anyway to get the current state of the mouse button during a mouse move other than using game.input.mousePointer.button? 

Thanks!

-Kadith

Share this post


Link to post
Share on other sites

I see the same behavior in the latest version of Phaser CE, as well as in the Phaser input example (https://phaser.io/examples/v2/input/mouse-buttons) in the latest versions of both Chrome and Firefox.

Seems appropriate to file a bug for investigation ☺️

Here's more information on how to do so: https://github.com/photonstorm/phaser-ce/blob/master/.github/CONTRIBUTING.md#reporting-issues

In the meantime, you can use the middle mouse button's onDown and onUp events to set a variable that tracks whether the button is down. Here's an example: https://codepen.io/giniwren/pen/LrwjYZ

Share this post


Link to post
Share on other sites
6 hours ago, samme said:

Pointer#button isn't actually the button that's currently down, it's the button associated with the last mouse event.

Shouldn't the last event still have it registered as down in that case if the button hasn't released it? Or does that only get set when the button is pressed?

 

Quote

Use mousePointer.middleButton.isDown instead.

Worked like a charm thanks!

 

Share this post


Link to post
Share on other sites

I think right now Phaser updates Pointer#button for all mouse events, not just mouseup/mousedown. And browsers report button=0, also identical to LEFT_BUTTON, for other mouse events.

Share this post


Link to post
Share on other sites

If it's the browser then guess there's not much they can do about it (at least not easily).

Checking the mousePointer directly is working great though so thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.