How long has the player tapped on the iOS/Android display screen? How can I measure the time?

Kim Strasser 876 Reputation points
2024-07-22T14:08:15.7066667+00:00

In my game the player needs to tap on the iOS/Android display screen to make a gameplay action. I want to find out how long the player pressed his finger against the display screen. For example, if the player pressed his finger 1 second on the screen than I could make a different or stronger action when the tap gesture is finished. I thought maybe I could multiply the time of the tap gesture with another value to determine the strength of a gameplay action in my game.

For example: Strength of gameplay action = xx seconds * 1000

But I don´t know how to measure the time that the finger was on the screen. How can I measure the time of the tap gesture?

  TouchPanel.EnabledGestures = GestureType.Tap | GestureType.FreeDrag | GestureType.DragComplete;

  while (TouchPanel.IsGestureAvailable)
  {
      GestureSample gs = TouchPanel.ReadGesture();
      switch (gs.GestureType)
      {
          case GestureType.Tap:
          //  Strength of gameplay action = xx seconds * 1000  ?

          break;
          case GestureType.FreeDrag:

          break;
          case GestureType.DragComplete:

          break;
     }
 }
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,877 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,221 questions
{count} votes