MarvinB

Click Function Called Twice

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

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

  

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.