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

[2.4] Button callback doesn't trigger on click #1932

Closed
Chris-Carvelli opened this issue Jul 24, 2015 · 27 comments
Closed

[2.4] Button callback doesn't trigger on click #1932

Chris-Carvelli opened this issue Jul 24, 2015 · 27 comments

Comments

@Chris-Carvelli
Copy link

In 2.4.0, the button callback doesn't trigger on mouse click. With phone touch works fine (and the same code works under 2.3). Maybe related to the changes to Input.Mouse?

Code (trivial, but you never knows...):

var aButton = this.add.button(400, 300, 'aButton', function() {
            console.log('aButtonCallback');
                        //do stuffs
        }, this);
@photonstorm
Copy link
Collaborator

Can you test this against 2.4.1 please, as they seem to be working fine for me, but there were definitely issues in some browsers with click events on 2.4.0.

@Chris-Carvelli
Copy link
Author

In 2.4.1 aren't working both.

Browser: Firefox 39.0 (64bit, I'm pretty sure);
SO: Linux Mint 17 64bit;

EDIT: almost forgot:
Phone browser: Chrome 43.0
OS: Android 5.1.1;Nexus 5 Build

@IanRamosC
Copy link

It's not working for me too.
It works on chrome for linux / chrome~firefox for windows.

@photonstorm
Copy link
Collaborator

Must be Linux specific. Works fine in Firefox 38, 39 and 41 on Windows and OS X.

In which case I need you to do this please: edit Pointer.start and at the top log out the event, build it and post the results up here. I don't have Linux running anywhere, but I'm surprised it doesn't include the buttons property. Actually you could probably get it by just logging out game.input.mouse.event after clicking.

@Chris-Carvelli
Copy link
Author

mousedown { target: <canvas>, buttons: 1, clientX: 409, clientY: 257, layerX: 409, layerY: 257 }

The event is catch properly. After a bit of debugging seems like the Phaser.Pointer.targetObject is set correctly and the touchedHandler executed. And indeed after the window regain focus the callback is correctly executed. After disabling all breakpoints and try again, the event is logged properly but the callback isn't executed again

@photonstorm
Copy link
Collaborator

Ok so that's weird - it's nothing to do with the mouse event itself then? and I can see you've got a buttons property too - so it much be the touchedHandler check itself that is failing? (even though I've barely touched that for ages)

@Chris-Carvelli
Copy link
Author

Ok, I debugged deeply and things became more strange.

First, the _toucherHandler is the same for 2.3 and for 2.4.1. THe only difference is in a test (but it's equivalent semantically) and in the comment.

Exactly in that test

if (!this._pointerData[pointer.id].isDown && this._pointerData[pointer.id].isOver)

The log showed
this._pointerData[pointer.id].isDown = false;
this._pointerData[pointer.id].isOver = true;
for a true test, and the logs in the true branch are showed correctly indeed.
For the following click instead this._pointerData[pointer.id].isDown = true; for a false test, and the logs in the true branch are correctly skipped.

This is because in the _releasedHandler, in the test

if (this._pointerData[pointer.id].isDown && pointer.isUp)

this._pointerData[pointer.id].isDown = true;
pointer.isUp = false;
so the true branch is skipped and the this._pointerData[pointer.id].isDown is never set to false again.
In 2.3 pointer.isUp is correctly set to true instead. I don't know if it's a bug or just a correct effect of the changes in 2.4.0 to the mouse pointer.

Still the first click should work fine, but the callback isn't executed

@Chris-Carvelli
Copy link
Author

Update: the code

var btn = this.game.add.sprite (200, 200, 'playButton');
        btn.inputEnabled = true;
        console.log(btn);
        btn.events.onInputDown.add(function() {
            console.log('________________callback executed________________________');
            //doStuffs
        }, this);

works for the first click and skip the following, as espected

@danbolt
Copy link

danbolt commented Jul 26, 2015

Button callbacks are working for me with 2.4.1 on Mac OS X and Chrome, but they do not happen on CocoonJS 2.1.1.2.

photonstorm added a commit that referenced this issue Jul 27, 2015
…ter on touch devices, which broke things like Sprite input events when built to native apps or run locally (#1932 #1943)
@photonstorm
Copy link
Collaborator

Could you all please try the latest build in the dev branch. I've uploaded build files as well for you. But I am pretty sure I've found the cause of it and in my tests in native Cordova apps and on Windows and OSX it's working correctly once again.

@Chris-Carvelli
Copy link
Author

v2.4.2 "Altara" - Built: Mon Jul 27 2015 13:35:06

Works for Linux Mint and Chrome. Same problem as before for firefox (39.0, up to date). First click detected but callback not executed, onReleaseHandler doesn't set the pointerData.isDown to false and the following clicks are ignored bu the touchedHandler

@photonstorm
Copy link
Collaborator

Firefox on Linux I assume? because it works fine with FF on Windows and OSX.

@photonstorm
Copy link
Collaborator

Could you please try this for me? In Pointer.updateButtons what does FF log out for event.type and event.buttons ? (for both the click down and the release).

@Chris-Carvelli
Copy link
Author

Yes, I've tested only Linux 'cause the problem seems to appear only there. But I can see your point. As soon as I have a Win machine at hand (I hope before this night) I will test my code on it, just to be sure that it's a Phaser problem and not something crappy about my code

@Chris-Carvelli
Copy link
Author

Result from a single click, what is print and from who (PS: even if the event Mouse.move is present, the mouse wasn't moved in the test)

console.trace():
Phaser.Pointer.prototype.updateButtons()
Phaser.Pointer.prototype.start()
Phaser.Mouse.prototype.onMouseDown()
Phaser.Mouse.prototype.start/this._onMouseDown()

"event.type" "mousedown"
"event.buttons" 1


console.trace():
Phaser.Pointer.prototype.updateButtons()
Phaser.Pointer.prototype.move()
Phaser.Pointer.prototype.start()
Phaser.Mouse.prototype.onMouseDown()
Phaser.Mouse.prototype.start/this._onMouseDown()

"event.type" "mousedown"
"event.buttons" 1


console.trace():
Phaser.Pointer.prototype.updateButtons()
Phaser.Pointer.prototype.stop()
Phaser.Mouse.prototype.onMouseUp()
Phaser.Mouse.prototype.start/this._onMouseUp()

"event.type" "mouseup"
"event.buttons" 1

@photonstorm
Copy link
Collaborator

Interesting - so it does actually have the buttons property, but the value is always 1.

@Chris-Carvelli
Copy link
Author

Yep. Instead of an array of buttons, it's set to 1 for the left click, 2 for the right click, etc.

@justy777
Copy link

I've been having the same problems.
Browser: Firefox 39.0 (64bit)
OS: Linux Fedora 22 (64bit)

While trying to debug the problem I discovered something that may help narrow down the problem.

In Firefox, I brought up the Developer Debugger, and on the right side under Events checked off mousedown and mouseup. Then, I went to click on a Button object, and when the debugger stops the script I click the button a few times, hold down Ctrl, step over one line of code, and press play.

After that, the callback gets called.

@photonstorm
Copy link
Collaborator

I think the only way to debug this properly is for me to install a VM or similar. Any recommendations on distros?

@Chris-Carvelli
Copy link
Author

Ubuntu 14.04 or 15.04, those are the most common

@photonstorm
Copy link
Collaborator

I have Ubuntu 14 running at the moment and can replicate it - the buttons value is populated, but utterly incorrect. Adding in a work-around now.

@photonstorm
Copy link
Collaborator

Ok this should be good now - please try the new dev branch build

@Chris-Carvelli
Copy link
Author

Works fine on Firefox 39.0, Linux Mint 17 64bit

@justy777
Copy link

Works on Fedora 22 as well :)

@photonstorm
Copy link
Collaborator

Awesome :) Will do some more tests on touch devices, but it's looking good for 2.4.2 this week then.

@danbolt
Copy link

danbolt commented Jul 28, 2015

Touch controls work with v2.4.2-dev on CocoonJS v.2.1.1.2 now! Thanks so much @photonstorm ! I think I'm going to upgrade from 2.2.1.

I'm excited to see these changes into release!

@photonstorm
Copy link
Collaborator

Awesome. I'll push out 2.4.2 today then.

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

No branches or pull requests

5 participants