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.
these are the events:
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:
I have already tried the “multi touch joystick” extension but it does not give way to create dynamic joysticks as in my case
Try to display the two joystick touch ids and the two lastendedtouchids in a text object when the issue occurs, to find out what’s going on.
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
You don’t want this :
It only checks the last ended touch, not all of them.
You should be doing it this way :
thanks mr men seems to go! when releasing the joysticks I no longer have the problem.
now the problem is only when they are pressed together
You’ll need to apply the same logic - use the JoyStick.MultiTouchJoyId to get the position of the touch that started on each button.
Have a look at the GDevelop MultiTouch example to see how it’s been done in that.
sorry for my confusion, I don’t understand where to apply I’m having great difficulty understanding multitouch … where am I wrong?
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.
not sure if this is correct? i can’t get it to work i’m going crazy
Probably because you are using the variable of LeftButtonBackgroud to control LeftButton.
i tried to change the variable like this but that seems to be not the problem …
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.
TouchId should be a number, not a string.
I’m very confused, even in the multitouch example TouchId is a string
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.
@ilary27, I’ve updated the game JSON. The link to it is here.
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).
So I’ve updated the game file to reflect this :
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.
Thank you so much mr men you are fantastic! that was what I was trying to achieve, I just don’t know how to thank you! you are unique!!!