Sign in to follow this  

Which socket connections clicked on the canvas with

Recommended Posts


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 == {
			remotePlayers[i].currentTurn = true;
	//update current player turn on server
	for (var i in cPlayers) {
		if (cPlayers[i].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


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.