Virtual Joystick Control for Android

Heya…

Added a virtual joystick control for android.

Video from PC:
[video]http://youtu.be/jSc6LZwEl-w[/video]

And… for no real reason… here is a random screen from testing on my tablet:

Now… I could use some assistance from someone who knows a bit about dealing with touch events in JME. I’d like to be able to handle multiple touch events at the same time. Is this possible? How does one work with? A link to any docs would be very helpful!

Thanks in advance.

6 Likes

Thanks. This saves me like 6 months of development. This feature had been in my mind for a long time!

I can help. Since I’m the person creating the gamepad support for android, and I’ve also used multi-touch for my previous game engine, I know a lot about this stuff.

Ok, I found this. Which is enough information to achieve your goal. However, the best tutorials are in the books called “Beginning android” and “Pro android”. I access them for free through my college library though (I’m a college student).

For the JInput part, I suggest you follow this post. This post is brand spanking new to tell you the least.

Count me in, for helping you on this!

1 Like

nice work.

I once wrote a simple joystick manager for n virtual joysticks. You always have to care about the touch id. If it helped you, I can send you the code.

@Erebos3D said: I once wrote a simple joystick manager for n virtual joysticks. You always have to care about the touch id. If it helped you, I can send you the code.

Funny you should mention this. I just committed an update that adds multi-touch support for the entire library. =)

1 Like

My joysticks weren’t for your library, I used them some time ago. They worked quite similar to your gui, so the code might have fit for you, too.

And at the moment I have no time to update the gui because I am having trouble with my Bluetooth server + client. I might be a little late :wink:

@Erebos3D said: My joysticks weren't for your library, I used them some time ago. They worked quite similar to your gui, so the code might have fit for you, too.

And at the moment I have no time to update the gui because I am having trouble with my Bluetooth server + client. I might be a little late :wink:

Ewww… sorry to hear about this.

And… I’d love to see how you went about this.

@t0neg0d

Did you complete multitouch for android?

Also, did you complete multitouch for JInput? If not, don’t worry it is easy to test. You just need two mice like it says in what I previously posted.

Sorry I have to ask. I don’t have time to run your program at this moment.

@Pixelapp said: @t0neg0d

Did you complete multitouch for android?

Also, did you complete multitouch for JInput? If not, don’t worry it is easy to test. You just need two mice like it says in what I previously posted.

Sorry I have to ask. I don’t have time to run your program at this moment.

I’ve implemented multi-touch via JME’s raw input listener… all seems to works really well.

I have not done anything with JInput past reading yet! And would definitely appreciate any help (if and when you have time)!

I guess I’ll start working on Jinput multitouch next week. I should buy an extra mouse by then.

wow nice work =D! I might try to use this with the game I’m working on just to try it out.

sidebar: I actually thought your gui system didnt work in android for some reason. i tried to do it once a couple weeks ago and i got an error and just assumed it wasnt android ready. I might have to revisit that.

@icamefromspace said: wow nice work =D! I might try to use this with the game I'm working on just to try it out.

sidebar: I actually thought your gui system didnt work in android for some reason. i tried to do it once a couple weeks ago and i got an error and just assumed it wasnt android ready. I might have to revisit that.

This was the case up until a few days ago (when I finally figured out the piece I was missing for testing on my tablet). All should be in working order now. Just grab the latest commits from the repo and you’re good to go. By default, the screen does not handle multi-touch… you have to call screen.setUseMultiTouch(true); when initializing it (Sort of important if your using a virtual joystick or two and wanting to be able to interact with other things as well)

EDIT: Just found out what I was missing. Always happens right after posting. Had to include the android-base library

I’m still new to jme but I’m attempting to learn it in order to make Android apps specifically. I was looking through the forums for a Virtual Joystick and came across this thread.

this joystick is exactly what I was hoping for and looks great. How would I go about accessing this code? I created a copy of jme that uses the latest nightly build.

Looking through the javadocs I found AndroidSensorJoyInput. I tried to access this in my nightly build project but the import doesn’t exist.

I feel that I’m missing something obvious but I couldn’t find any older post that showed where this code might be.

Thanks for any help you can provide.

@t0neg0d

I’ve been looking for some ideas for a better keyboard interface for jME. I noticed in your screenshot above you have a virtual keyboard displayed and was wondering what method you used for that.

@iwgeric said: @t0neg0d

I’ve been looking for some ideas for a better keyboard interface for jME. I noticed in your screenshot above you have a virtual keyboard displayed and was wondering what method you used for that.

Sorry for the delay in response. Ummm… method? Specific to the library? or just how I put it together in general?

If specific to the library… when setting up the screen:

[java]
screen = new Screen(this, “tonegod/gui/style/atlasdef/style_map.xml”);
screen.setUseTextureAtlas(true,“tonegod/gui/style/atlasdef/atlas.png”);
screen.setUseMultiTouch(true);
guiNode.addControl(screen);
[/java]

The keyboard is active if android is detected. If you want fancy icons on the keyboard use:

[java]
screen.setUseKeyboardIcons(true); // << this is it
[/java]

Any text-based input control from the library will call up the virtual keyboard.

If NOT specific to the library, the control is build from the generic components and since all input is delegated from the screen class, it is easy to to intercept and force the virtual keyboard. I’m sure this could be easily mimicked using another library… well… time consuming… but doable.

If this didn’t answer the question, just let me know!

EDIT: Also, the source code is available… between the VirtualKeyboard, the TextBox and Screen classes anything you might want to know specifically is all there. I can answer any specific questions if you’re porting it to another library. Just need to know the specific question! =)

@t0neg0d

Thanks. I was just curious if the keyboard image was a single image with coordinates for the keys or a bunch of separate objects (1 per key).

The last time I did something similar, I went down the road of 1 image with coordinates for each key. Was just curious if this was the same approach you used or not.

I’m also going to be looking into integrating the platform native keyboard(s) into jME. I think it will be something like:
option 1: bring up the keyboard and each keypress goes to inputManager
option 2: bring up the keyboard and just return the complete string when the keyboard is dismissed

Any comments you might have would appreciated. Want to make sure what I do will be useful to your library as well.

1 Like
@iwgeric said: @t0neg0d

Thanks. I was just curious if the keyboard image was a single image with coordinates for the keys or a bunch of separate objects (1 per key).

The last time I did something similar, I went down the road of 1 image with coordinates for each key. Was just curious if this was the same approach you used or not.

I’m also going to be looking into integrating the platform native keyboard(s) into jME. I think it will be something like:
option 1: bring up the keyboard and each keypress goes to inputManager
option 2: bring up the keyboard and just return the complete string when the keyboard is dismissed

Any comments you might have would appreciated. Want to make sure what I do will be useful to your library as well.

Couple thoughts:

The virtual keyboard in this library has single tap types the key once… if you press and hold (after a short delay) it will repeatedly send the key event at a certain interval.

Just wanted to make sure this would be part of the standard keyboard. Likely that it would have been anyways. Just wanted to mention it.

@t0neg0d said: Couple thoughts:

The virtual keyboard in this library has single tap types the key once… if you press and hold (after a short delay) it will repeatedly send the key event at a certain interval.

Just wanted to make sure this would be part of the standard keyboard. Likely that it would have been anyways. Just wanted to mention it.

I’ve been playing around with a native keyboard sending keys to inputmanager. It looks like the native keyboard doesn’t send repeated keys. There is a parameter in the Android KeyEvent that is supposed to indicate “repeating” but it isn’t set when I hold the key down. Maybe some of the soft keyboard implementations in Android don’t send it.

On the keyboard my phone uses, a long press brings up alternate keys. For keyboards with that functionality, the OS may not send repeated key events. I’m not sure I can detect this automatically. This function might need to be implemented on the app side.

@t0neg0d where do I get the code for virtual joystick? I would like to use it now.

@Pixelapp said: @t0neg0d where do I get the code for virtual joystick? I would like to use it now.

You can find this in either the download section of the repo (latest build)… or you can grab the sources if you are interested in any of the latest additions as well (Pool, etc)

Also, on a side note. If you are using the joystick as a d-pad, you’ll need to do something along the lines of this:

[java]
if (FastMath.abs(deltaX) > FastMath.abs(deltaY)) { // X-Axis dominance

} else { // Y-Axis dominance

}
[/java]

Yeah… obvious to some… but thought I would mention it anyways.