Touches are handled as events in UrhoSharp, and this means that they require event handlers. Let's create a handler for the TouchBegin event by going through the following steps:
- In the WhackABox project, open the Game.cs file.
- Add the OnTouchBegin() method anywhere in the code, as shown in the following code snippet:
private void OnTouchBegin(TouchBeginEventArgs e)
{
var x = (float)e.X / Graphics.Width;
var y = (float)e.Y / Graphics.Height;
DetermineHit(x, y);
}
When a touch is registered, this method will be called, and information about that touch event will be sent as a parameter. This parameter has an X and a Y property that represent the point on the screen that we have touched. Since the DetermineHit() method wants the values in the range of 0 to 1, we need to divide the X and Y coordinates by the width and height of the screen.
Once that is done, we call the DetermineHit() method. To complete this section, we...