title: How to check for tap in monogame?
body: <p>I want to check that <code>Rectangle</code> was tapped. This mehod does the job and it works almost how I want:</p>
  
  <pre><code>private bool CheckRectangleTouch(Rectangle target)
  {
      var touchCollection = TouchPanel.GetState();
      if (touchCollection.Count &gt; 0)
      {
          foreach (var touch in touchCollection)
          {
              if (target.Contains(touch.Position))
              {
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>
  
  <p>Problem I have is that after I've tapped rectangle it keeps returning <code>true</code> until I release it (it can register 10-30 times for one tap) and I want it to return <code>true</code> just once - for the first touch.</p>
  
  <p>I've tried this (replace code inside <code>foreach</code>):</p>
  
  <pre><code>            var isFirstTouch = !touch.TryGetPreviousLocation(out _);
              if (target.Contains(touch.Position) &amp;&amp; isFirstTouch)
              {
                  return true;
              }
  </code></pre>
  
  <p>And this (bad one, I don't really want it to register after release):</p>
  
  <pre><code>            if (target.Contains(touch.Position) &amp;&amp; touch.State == TouchLocationState.Released)
              {
                  return true;
              }
  </code></pre>
  
  <p>But nothing is does it. Either logic is not consistent or doesn't work at all.</p>
  
  <p>So how do I check for tap?</p>
  
  <p>Update: this works but it's very hacky, has delay and gives me random phantom taps:</p>
  
  <pre><code>    try
      {
          var tap = TouchPanel.ReadGesture(); // falls each time when no input
          return tap.GestureType == GestureType.Tap &amp;&amp; target.Contains(tap.Position);
      }
      catch { }
  
      return false;
  </code></pre>