Hi guys, I have to ask you for a big hand in solving my multitouch problem.
I have been working on a mobile video game for a long time, I am currently using this example for multitouch
the problem arises when you touch or release the joysticks at the same instant, the second touch is not recognized.
I hope someone can help me, I included this example in my whole game and changing it would be starting all over again.
I don’t see anything wrong with your events.
Perhaps there’s a limitation to “LastEndedTouchId” if multiple touches are released at the exact same frame.
There’s a new joystick extension, I can only recommend you try it:
in the example sent the variables are already inserted in a text object … when the controllers are pressed or released at the same time only the first touch or release is considered.
so let’s say that they are released together one of the two joysticks remains pressed towards the release direction.
they do not work independently
That screen snip is for when the touch is initiated. So it’ll only get called once whenever a touch has started.
You’ll need another unconditional event (outside of the new touch has started event) to position the button based on the associated touchId. I suggest you move the position change actions for LeftButton and LeftButtonBacGroud from the screen snip event and into this new unconditional event.
now when the joystick is started and released it is positioned in the x 0 y 0 axis and remains fixed there not recognizing the other touches.
what i don’t understand is how does it change the “left button” position based on the “lefbuttonbackground” variable when it is not present in the “leftbutton” variable.
the only active variable is touchid
Yes, because when the touch is released, it doesn’t exist any longer. You need to check the touch is still valid before you move the buttons.
If the touch has finished, then MultiTouchJoyID is an id to something that doesn’t exist. Therefore TouchX(…) tries to get the position of a touch that doesn’t exist. As a result, GDevelop uses the default value of 0 as the return value for the TouchX() function.
It will change type to a number if that’s how it’s used. But it’s better to declare them the right type so there’s no confusion of what they should contain.
But that was just an aside. The rest of the post is what is important to your issue.
I tried to follow your advice but I think I am not able to understand on my own. I would be very grateful if as soon as you have a free moment to open the project and take a look at the code. please mr.men you are the only one who can help me solve this problem.
It appears LastTouchId() isn’t used any longer - maybe it’s been deprecated. It wouldn’t come up in the list of possible functions, and it looks like it’s been replaced with StartedTouchId(number).
When multiple touches are made in the same frame, they appear to be put into an array type structure, and they are retrieved using the array number. So for example if there are 2 touches, the first is obtained with StartedTouchId(0), and the second with StartedtouchId(1).
If I read your code correctly, you are placing the joystick controls where the touch is within a certain area of the screen, rather than have it as a fixed position on the screen. Knowing this, earlier suggestions may not have worked the best.
Anyway, the fix is done, it works for two simultaneous touches, one on each joystick area.