mla Posted October 23, 2018 Share Posted October 23, 2018 Hi, I'm wondering how to avoid simultaneous mousedown events. I have a canvas drawn on screen. When a player clicks events take place based on where the player clicked on the screen. If two players click the canvas at the exact same time, they should both be alerted with a message that no simultaneous moves are allowed. I used an array to capture the move, however it seems to only register the move after the check and not before. Is there a simple way to capture which clients clicked at the same time? //Listen for player click event chainlinks.onmousedown = function(event) { var totCT; //update current player turn on client for (var i = 0; i < remotePlayers.length; i++) { if (remotePlayers[i].id == socket.id) { remotePlayers[i].currentTurn = true; } } //update current player turn on server for (var i in cPlayers) { if (cPlayers[i].id == socket.id){ cPlayers[i].currentTurn = true; } } socket.emit('update-currentTurn', {remotePlayers: remotePlayers, cPlayers:cPlayers}); if (totCT > 1) { //Simultaneous move happened - show invalid message } else { //All good to go ahead with the click event } } Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.