Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Joystick in Android SDK

I want to make a virtual joystick in my Android application for controlling an RC car. How can I accomplish this? Is there an API that I can use to do this? The code samples that I have checked out online do not seem to work.

like image 949
Anish Muthali Avatar asked Oct 10 '16 18:10

Anish Muthali


1 Answers

You can have a look at this one, very simple (with documentation, etc.) https://github.com/controlwear/virtual-joystick-android

Just add to your build.gradle file compile 'io.github.controlwear:virtualjoystick:0.9.9' and then:

JoystickView joystick = (JoystickView) findViewById(R.id.joystickView);
    joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
        @Override
        public void onMove(int angle, int strength) {
            // do whatever you want
        }
    });

EDIT:

As of new updates, compile is obsolete, instead you should use implementation or api, as follows: implementation 'io.github.controlwear:virtualjoystick:1.10.1' (1.10.1 updated version)

The minSDK as the author says is 16 (Android Jelly Bean).

like image 148
makowildcat Avatar answered Oct 28 '22 13:10

makowildcat