Libgdx - 在函数中使用 void 作为参数

Libgdx - Use void as an agrument in a function

我正在尝试用 Void 作为 libgdx 中的参数创建一个 void, 我如何让它发挥作用?

这是我的:

public class ReleaseDetector{

        boolean Touched = false;

        //
        // --- Simple void for touch release detection, when looped. ---
        // --- and the argument void, or how i imagine it..
        //
        public void ReleaseListener(void MyArgumentVoid)//<---The argument void
        {
            if (Gdx.input.isTouched()){

                Touched = true;
            }
            if (!Gdx.input.isTouched() && Touched){
            MyArgumentVoid();<----------// Call for a void from the Argument.
            Touched = false;
            }
        }
}

在 MyGdxGame 中的用法 class,或者我的想象:

public class MyGdxGame extends ApplicationAdapter {

int Counter = 0;
ReleaseDetector RD = new ReleaseDetector();

    public void AddCounter(){// just a simple void.
        Counter++;
    }

    @Override
    public void render() { // Render Loop void.
    RD.ReleaseListener(AddCounter);// how i imagine it's usage.
    }
}

现在,我如何让它成为现实?我希望有一个简单的方法..

您似乎需要一个 回调方法 并且 returns void.

public class ReleaseDetector {

    boolean touched = false;

    public void releaseListener(MyGdxGame game) { // Argument
        if (Gdx.input.isTouched()) {
            touched = true;
        }
        if (!Gdx.input.isTouched() && touched){
            game.addCounter();                    // Callback
            touched = false;
        }
    }
}

public class MyGdxGame extends ApplicationAdapter {

    int counter = 0;
    ReleaseDetector detector = new ReleaseDetector();

    public void addCounter() {
        counter++;
    }

    @Override
    public void render() { // Render Loop.
        detector.releaseListener(this);
    }
}

希望对您有所帮助。