Games [XUI2D] Touchy example - X2Multitouch

Erel

B4X founder
Staff member
Licensed User
Longtime User
X2Multitouch simplifies the handling of fingers touches and keyboard.

It has two advantages:
1. Cross platform API.
2. It allows getting the state inside the tick event. This is much better than handling events outside of the game loop.

Usage:
1. Initialize X2Multitouch and pass the hosting B4XPage and the panels that will be tracked for touch events.
The event name of all these panels should be "Panel".
Note that the behavior of panels not added to the list will differ based on the platform. It is simpler to add all relevant panels.
2. Make sure that the following code is in the game module, it is part of the template:
B4X:
#If B4J
Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    Multitouch.B4JDelegateTouchEvent(Sender, Action, X, Y)
End Sub
#Else If B4i
Private Sub Panel_Multitouch (Stage As Int, Data As Object)
    Multitouch.B4iDelegateMultitouchEvent(Sender, Stage, Data)
End Sub
#End If

3. Get a single touch with Multitouch.GetSingleTouch or get all touches with GetTouches. GetSingleTouch will return an uninitialized object if there are no touches.
A touch gesture starts when the finger is "down" and ends when the finger is "up". The example shows how to find the touch state. Note that touches that have ended (FingerUp = True) will only return once.

YjLBw9hAzZ.gif


Example is available in github: https://github.com/AnywhereSoftware/X2

Sprite source: https://opengameart.org/content/character-sprite-walk-animation
 
Top