Jump to content

Click Function Called Twice


MarvinB
 Share

Recommended Posts

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 :D

 

Link to comment
Share on other sites

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

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

@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

  • 1 year later...
  • 3 years later...

  

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...