MarvinB Posted October 11, 2015 Share Posted October 11, 2015 Hi everyone, one of my functions is triggered twice for some reason. It is a simple click on an element. // the player stops touching the house confirmHouse(sprite, pointer) { console.log('confirmed'); // logs 2x confirmed if(MMM.candidateSprite == sprite && MMM.menuOpen == false){ var _this = this; ........ } } // function to set a single house with specific postion setOneHouse(posX, posY, id, reference){ var house = this.game.add.image(posX, posY, reference); house.id = id; house.anchor.setTo(0.5); house.inputEnabled = true; house.events.onInputDown.add(this.selectSprite, this); house.events.onInputUp.add(this.confirmHouse, this); console.log('House set'); // logs 1x house set MMM.backgroundobjects.add(house); }Is it due to the nature of the events.onInputUp function? This double execution of my confirmHouse function is causing some nasty problems. Hope you guys can help me Link to comment Share on other sites More sharing options...
bruno_ Posted October 11, 2015 Share Posted October 11, 2015 Where are you testing? Are you using keyboard, mouse, touch? Link to comment Share on other sites More sharing options...
MarvinB Posted October 11, 2015 Author Share Posted October 11, 2015 Mouse, but it will end up being for Android. Link to comment Share on other sites More sharing options...
bruno_ Posted October 11, 2015 Share Posted October 11, 2015 In the browser, emulator, where? Link to comment Share on other sites More sharing options...
jmp909 Posted October 11, 2015 Share Posted October 11, 2015 Are you using Firefox?https://github.com/photonstorm/phaser/issues/1464 Link to comment Share on other sites More sharing options...
MarvinB Posted October 11, 2015 Author Share Posted October 11, 2015 I am actually using the IntelXDK. I am setting a little timeout of 100ms now with some boolean logic to avoid the second call to be fired. I feel like this is kinda dirty though... the player will notice no difference, but I'd still rather have clean solution. Link to comment Share on other sites More sharing options...
bruno_ Posted October 11, 2015 Share Posted October 11, 2015 Does that happen also on a device? Link to comment Share on other sites More sharing options...
MarvinB Posted October 12, 2015 Author Share Posted October 12, 2015 It happens on the emulator. But the emulator always gets pretty close to the real thing. I haven't built the .apk yet with my most current version, because I am working a lot with backend stuff locally right now. The server is only fractially finished, that's why I don't wanna make a deployment. Without the server running, the button that is causing the issue, doesn't do anything. And building the .apk takes a while on my computer, because the game is already getting pretty big. So I am trying to avoid building it for now.Just knowing that it can potentially occur, is really not what I want. The timeout thing works for now, but for production I would prefer something cleaner. I read in other posts that it is a browser issue, I haven't seen a good solution though. Link to comment Share on other sites More sharing options...
drhayes Posted October 12, 2015 Share Posted October 12, 2015 I know this sounds dumb, but are you sure it's the same house each time? There are no other usages of confirmHouse in your codebase? Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 12, 2015 Share Posted October 12, 2015 Down is when the mouse goes down so that's 1. Up is when the mouse is released, so that's another 1. The onInput input events need a overhaul I believe, they are confusing. See here: https://github.com/photonstorm/phaser/issues/2133 For another issue with onInputOver firing twice as well. Link to comment Share on other sites More sharing options...
MarvinB Posted October 12, 2015 Author Share Posted October 12, 2015 @drhayes no it doesn't sound dumb. Any suggestion could help. Unfortunately it is only one house. ConfirmHouse has only that usage.@WombatTurkey I agree with they need overhaul. The thing is my Down function only selects my sprite. My up function is the one that for some reason is triggered twice. So up and down are not added. They have seperate functionality. Link to comment Share on other sites More sharing options...
MarvinB Posted October 12, 2015 Author Share Posted October 12, 2015 Agree with you* Added up together* Sorry could have checked that before I send my post Link to comment Share on other sites More sharing options...
bruno_ Posted October 12, 2015 Share Posted October 12, 2015 The emulator does that, it has a touch event and a mouse event. You can set max input pointers to 1, if you want, but if you run your game in the browser (without the emulator) or in a device it will run fine. Link to comment Share on other sites More sharing options...
MarvinB Posted October 13, 2015 Author Share Posted October 13, 2015 Thank Bruno! I will test that! Link to comment Share on other sites More sharing options...
FlashyGoblin Posted March 15, 2017 Share Posted March 15, 2017 Do you guys have a an example of the timeout that prevents Android from triggering two events when a button is pressed? I'm running into the same issue. Thanks! Link to comment Share on other sites More sharing options...
konato-debug Posted March 15, 2020 Share Posted March 15, 2020 this.submitButton.setInteractive().on('pointerdown', function(pointer, localX, localY, event) { if ((this.sys.game.device.os.desktop && !pointer.wasTouch) || (!this.sys.game.device.os.desktop && pointer.wasTouch)) { } }, this); My issue was due to double clicking in mobile caused by two pointers (touch and mouse), so I used this checking to allow only one pointer if its mobile. Link to comment Share on other sites More sharing options...
Recommended Posts