matthias-research / pages

My web page containing all the demos from my youtube channel "Ten Minute Physics" www.youtube.com/c/TenMinutePhysics
626 stars 132 forks source link

Bug: 04-pinball game runs failed in the real mobile browser #28

Open liumu96 opened 1 year ago

liumu96 commented 1 year ago

When I try to play this pinball game on my iPhone 13, I can't move the flippers. The page doesn't react to the touch action. I debugged the code and found that the problem lies with the touch.identifier. Initially, the flipper's touchIdentifier was set to -1. I checked if touchIdentifier >= 0 to determine if there was a press action.

this.touchIdentifier = -1;
var pressed = this.touchIdentifier >= 0;
if (flipper.select(touchPos)) {
    flipper.touchIdentifier = touch.identifier;
}       

The problem was the touch.identifier was not always >= 0, for example , it didn't work in iphone 13 (real phone not the web virtual phone.). So I changed the initial touchIdentifier to null, and determined the press action by checked if touch.identifier was null. The key code is as below:

this.touchIdentifier = null;
var pressed = !!this.touchIdentifier;
if (flipper.select(touchPos)) {
    flipper.touchIdentifier = touch.identifier;
}