-1

I want to develop a game with Javascript.

Two Players can play at the same mobile device. I will need a method to check, when a player clicks. The Problem is, that they can click at the same time. Therefore I tried JQuery and native Javascript methods to handle these clicks at the same time. But nothing works.

Is there a chance to do something like that?

PS: sorry for my bad english

raimannma
  • 13
  • 4
  • It would really be simultaneous touch events, not clicks. What issue are you seeing that you are trying to resolve? – Taplar Feb 16 '18 at 16:22
  • The players should click at the same moment and a function should count how often – raimannma Feb 16 '18 at 16:24
  • 1
    Again, touch events, not click. They aren't using a mouse. And again, what issue are you seeing? You are saying what it should do. You are not saying what it is doing incorrectly. – Taplar Feb 16 '18 at 16:25
  • If you are able to identify the players, you should apparently identify touch as well. All touch events will be invoked – G_S Feb 16 '18 at 16:26

1 Answers1

0

As the others have mentioned, you're going to want to use touch events rather than clicks since you're developing for mobile. This should get you started:

$(function() {
  var touchCount = 0;
  
  $('button').on({'touchstart':function(e) { 
    e.preventDefault();
    touchCount++
    $('.count').text(touchCount);
  }});
});
button {
  height:50px;
  width:100px;
  margin-left:50px;
}
  button:first-child {
    margin-left:0;
  }
  
span {
  display:block;
  margin-top:50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="button">
  <button>Player 1</button>
  <button>Player 2</button>
</div>

<span class="count"></span>
APAD1
  • 13,509
  • 8
  • 43
  • 72