Ask here your questions to get help using GDevelop.
By steveang9999
#69801 Guys, i been working on a platformer game for android, currently having some problem for the movement controls. I want to be able to move the character smoothly left or right without releasing the touch on screen. How do i achieve something like this? Currently i am using 2 buttons and event of checking if cursor on sprite, then simulate movement to left and right. But when i want to move from left button(sprite) to right button(sprite), the movement stopped and i have to retouch the screen again to be able to move to other direction.

Just want to know how to do like as long as i am touching on the screen on phone, i will be able to move left or right without releasing the touch by just dragging my finger around with just 1 button(sprite) on screen?
User avatar
By ddabrahim
#69803 I thought we have an example for that :?
Anyway I have just created one, you can find it at the bottom of the list:
https://gametemplates.itch.io/gdevelop-examples

The idea is, instead of moving the character on button press, get a center point and compare the position of touch to the center point. If the position of the touch is greater than the position of the center point move right if less move left.
By steveang9999
#69808 hmm, first of all, thanks alot for your reply ddabrahim! Regarding the center point really is what need :) but is it possible to achieve like the button move to right or left whenever touch is on the movement button?. What i mean is we have a big circle, inside theres a round button, so whenever finger touch, when comparing distance from center, the round button moves but still stay inside the circle.
User avatar
By ddabrahim
#69810
is it possible to achieve like the button move to right or left

Actually it doesn't necessary to control character with a button movement.
Pick a base sprite, either an invisible or the circle for example.
Pick the center point of this base and move the character by taking in to account the position of the touch compared to the center position of this base as I explained.
End then, only as a visual effect, add the button and make it move left and right based on how much the user move the pointer left and right by taking in to account the distance between the center point of the base and the position of the touch.
So for example if the touch is 40 pixels from the center, move the button 40 pixels to the right but obviously use a variable that constantly store the current distance then apply It on the button...

You also want to implement some sort of limit too so the player can not drag the button all over the screen and stop at the edge of the circle for example.

I don't have time right now to update the example if no one else come up with an example for you I'll do it when I have time later.
User avatar
By ddabrahim
#69817 Updated the example. It has a proper joystick that move around with your thumb. It is also multy touch enabled so you can move and jump the same time. I have also tested on mobile and works nicely.
The joystick is hard coded for now, if you want to change the position of the joystick on the screen you also need to change the X and Y values in the events accordingly.

The Joystick could use some polish, but I hope it helps to get the basic idea how to implement one :)
By steveang9999
#69962 Guys, I tried to follow the example, and it works but after i open the gdevelop second time, it appears to be some problems with the control, wondering if this is a bug. Check the command below:


https://imgur.com/a/gtCYz4E


so if the touch location is > than the centre of joystickbgm, it should move right for player, but no matter where i touch, it will move left. Is there anything wrong with these code?
User avatar
By ddabrahim
#69965
f the touch location is > than the centre of joystickbgm, it should move right for player, but no matter where i touch, it will move left

If it moves left, that means for some reason it returns 0 and so the touch always less <
Not sure what is going on, you say it did work the first time right?

If touch < center = left
if touch > center = right

Sounds good to me :?

I'll have a look when I got some time if no one else figure out.
User avatar
By ddabrahim
#69967 I noticed you are using a different object name called JoyStickBgm. In my example it called ButtonBg.
Just tried it and it still works on my end.
Download the example form itch again if you can't fix it on your end :)