XverhelstX Well-Known Member Licensed User Longtime User Aug 28, 2011 #1 Hello everyone, I'd like to make my first topdown game but without the typical arrow direction pad. I'd like to use a joystick to move the main character around in different directions. Does anyone has an example or example code on how to do this? I prefer using a sprite (image) as the joystick pad. So when touching the 'circle' at the left, the main character walks to the left. I'm sure this will help a lot of other people. here's an example screenshot: XverhelstX
Hello everyone, I'd like to make my first topdown game but without the typical arrow direction pad. I'd like to use a joystick to move the main character around in different directions. Does anyone has an example or example code on how to do this? I prefer using a sprite (image) as the joystick pad. So when touching the 'circle' at the left, the main character walks to the left. I'm sure this will help a lot of other people. here's an example screenshot: XverhelstX
thedesolatesoul Expert Licensed User Longtime User Aug 28, 2011 #2 The joystick has the addition advantage of being able to sense magnitude as well as direction. This should be fairly easy to program. I do not have an example but I can give some ideas. If you have a rectangle for the joystick, you will need to sense the Touch coordinates and find the distance and angle from origin (centre of the rectangle). The sprite for the joypad will probably always be centred at Touch coordinates. Have a look at how Gameloft's NOVA does it. Attachments 23966.jpg 92.2 KB · Views: 758 Upvote 0
The joystick has the addition advantage of being able to sense magnitude as well as direction. This should be fairly easy to program. I do not have an example but I can give some ideas. If you have a rectangle for the joystick, you will need to sense the Touch coordinates and find the distance and angle from origin (centre of the rectangle). The sprite for the joypad will probably always be centred at Touch coordinates. Have a look at how Gameloft's NOVA does it.
K Kamac Active Member Licensed User Longtime User Aug 28, 2011 #3 Good question you have I will try to look for some ready samples from java. Here's some 'concept' for this to work. Attachments conceptjoy.jpg 13.3 KB · Views: 787 Upvote 0
Good question you have I will try to look for some ready samples from java. Here's some 'concept' for this to work.
Djembefola Active Member Licensed User Longtime User Aug 28, 2011 #4 Hi, i've attached a quick and dirty example how to make a joystick control in b4a. Attachments joystickdemo.zip joystickdemo.zip 24.5 KB · Views: 829 Upvote 0
K Kamac Active Member Licensed User Longtime User Aug 28, 2011 #5 Nice joystick Djembefola It did lack recognision of distance, so i added it :sign0060:! It now speeds up as you move the joy away. PS. Maybe someone will actually update it so joystick can move ? Attachments joystick_updated.zip joystick_updated.zip 24.7 KB · Views: 723 Upvote 0
Nice joystick Djembefola It did lack recognision of distance, so i added it :sign0060:! It now speeds up as you move the joy away. PS. Maybe someone will actually update it so joystick can move ?
thedesolatesoul Expert Licensed User Longtime User Aug 28, 2011 #6 Thanks Djembfola I havent seen Kamac's modification yet Here is some more modifications which detects both magnitude and angle (before it was just an 8 directional D-PAD, now it can move in any direction almost) EDIT: btw, my code is really bad and hacky! Attachments test(Mag,Angle).zip test(Mag,Angle).zip 24.5 KB · Views: 689 Upvote 0
Thanks Djembfola I havent seen Kamac's modification yet Here is some more modifications which detects both magnitude and angle (before it was just an 8 directional D-PAD, now it can move in any direction almost) EDIT: btw, my code is really bad and hacky!
XverhelstX Well-Known Member Licensed User Longtime User Aug 28, 2011 #7 Thanks a lot thedesolatesoul, kamac and Djembefola! However, i'm searching more to move in all directions. Now it is 8 directional movement. Is it also possible to add a joystick as i tried it, but I couldn't figured it out. :S Thanks! XverhelstX EDIT: Oh, I just saw thedesolatesoul's one that support all directional movement. Now I only need the moving joystick there's a small bug in the one from thedesolatesoul though. sometimes moving up and down switches :s It's very helpfull for me and for others that will use it Thanks a lot guys! Last edited: Aug 28, 2011 Upvote 0
Thanks a lot thedesolatesoul, kamac and Djembefola! However, i'm searching more to move in all directions. Now it is 8 directional movement. Is it also possible to add a joystick as i tried it, but I couldn't figured it out. :S Thanks! XverhelstX EDIT: Oh, I just saw thedesolatesoul's one that support all directional movement. Now I only need the moving joystick there's a small bug in the one from thedesolatesoul though. sometimes moving up and down switches :s It's very helpfull for me and for others that will use it Thanks a lot guys!
thedesolatesoul Expert Licensed User Longtime User Aug 28, 2011 #8 XverhelstX said: there's a small bug in the one from thedesolatesoul though. sometimes moving up and down switches :s Click to expand... Yes, it is a weird bug. Maybe I should have used AtanD instead of Atan, and done all calculations in degrees. Upvote 0
XverhelstX said: there's a small bug in the one from thedesolatesoul though. sometimes moving up and down switches :s Click to expand... Yes, it is a weird bug. Maybe I should have used AtanD instead of Atan, and done all calculations in degrees.
Djembefola Active Member Licensed User Longtime User Aug 28, 2011 #9 smooth, thedesolatesoul !! works perfect, you just forgot to comment out two lines of code. Last edited: Aug 28, 2011 Upvote 0
maleche Active Member Licensed User Longtime User Oct 31, 2011 #10 Tank Style Steering Hello, I am working on an application to control a robot with Tank Steering. I have programmed an interface and the vertical sliders (throttles) work individually but not at the same time to control both motors. The vertical sliders are ImageView inside two separate (vertical) Panels. The Slider Knob (ImageView) moves vertically and returns min and max values. The camera joystick is an ImageView (Ball) inside another Panel to control the camera x & Y Pan/Tilt and works well. What is the best way to program the Vertical Sliders to operate at the same time? See attached Graphic. Thank you! Attachments Test1.jpg 20.6 KB · Views: 872 Upvote 0
Tank Style Steering Hello, I am working on an application to control a robot with Tank Steering. I have programmed an interface and the vertical sliders (throttles) work individually but not at the same time to control both motors. The vertical sliders are ImageView inside two separate (vertical) Panels. The Slider Knob (ImageView) moves vertically and returns min and max values. The camera joystick is an ImageView (Ball) inside another Panel to control the camera x & Y Pan/Tilt and works well. What is the best way to program the Vertical Sliders to operate at the same time? See attached Graphic. Thank you!
Erel B4X founder Staff member Licensed User Longtime User Oct 31, 2011 #11 You should use the Gestures library: Basic4android Search: Multitouch tutorial Upvote 0
Fusseldieb Active Member Licensed User Longtime User Sep 16, 2014 #12 Two lines of code has caused the bug which switched the controls up/down randomly. Aaand....I have made the joystick move now It runs all smooth here. Project attached Attachments Joystick_Moving.zip Joystick_Moving.zip 12.5 KB · Views: 673 Last edited: Sep 16, 2014 Upvote 0
Two lines of code has caused the bug which switched the controls up/down randomly. Aaand....I have made the joystick move now It runs all smooth here. Project attached