Virtual Joystick in Android SDK
Asked Answered
R

1

5

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.

Repartee answered 10/10, 2016 at 18:39 Comment(0)
C
9

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).

Crimple answered 21/10, 2016 at 23:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.