Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset button position only appears to be working from within setOnMoveListener #37

Open
JohanJarvi opened this issue Apr 13, 2021 · 0 comments

Comments

@JohanJarvi
Copy link

Firstly some basic information about the App Gradle setup:

compileSdkVersion 30
buildToolsVersion '29.0.2'
defaultConfig {
    minSdkVersion 24
    targetSdkVersion 30
    ...
}

Secondly the dependency of this library currently used:
implementation 'io.github.controlwear:virtualjoystick:1.10.1'

The problem

It appears that when calling .resetButtonPosition on a JoystickView as such:
joystickView.resetButtonPosition();

It does not in fact reset the position.

How it is being used

Right now I am calling the reset button position method through an onClick of a different onscreen button. Essentially what it aims to do is that when one joystick has the auto recenter button set to false the button exists to be able to basically "reset it" back to center. But this does not work.

I am using this method to set autoReCenter to false:
joystickView.setAutoReCenterButton(isSticky);
Where "isSticky" is just a boolean that is confirmed to be toggling correctly from true/false as it does in fact change the joystick behaviour accordingly.

I have noticed that the behaviour of the joystick does not change onClick unless the setOnMoveListener is re-instantiated and perhaps that can be cause of the issues.

Full code example

JoystickView rightJoystick = findViewById(R.id.rightJoystick);

Button autoRecenterButton = findViewById(R.id.joystick_sticky);

autoRecenterButton.setOnClickListener(new View.OnClickListener() {

    boolean isSticky = false;

    @Override
    public void onClick(View v) {
        isSticky = !isSticky;

        // This works correctly
        rightJoystick.setAutoReCenterButton(isSticky);

        // This does not appear to work correctly
        rightJoystick.resetButtonPosition();

        // A new listener needs to be set when button was toggled
        // in order to change the auto recenter behaviour
        rightJoystick.setOnMoveListener((angle, strength) -> {
            // do joystick things
        }, 25);
    }
});

Desired outcome

For the other on screen button to toggle whether or not the joystick is sticky but then if doing from "non-sticky" to "sticky" it needs to also reset the position of the joystick back to center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant