Libgdx - 如何在触摸按钮时退出应用程序?

Ligbdx - How to exit app when touch a button?

我想知道如何在触摸按钮时退出我的 libgdx 应用程序。

Inside class that implements Screen and InputProcessor.

public void show(){
    ........
    exitButton= new TextButton("Exit", style);
    exitbutton.setPosition(50,50);
    ........
}
public void render(){
    ........
    exitButton.draw(batch, 1f);
    ........
}

现在如何以及在何处设置触摸此按钮时退出应用程序的条件?

如果您有一个实现了 InputProcessor(接口)的 class,您必须实现 InputProcessor 的方法。通常会使用 Stage class(其中具有这些方法的实现)。但是如果你不使用它,你需要自己做,否则你的代码将无法编译。您具体要找的方法很可能

boolean touchDown(int screenX, int screenY, int pointer, int button)

在此处放置您的代码以确定应用程序退出。如果你没有收到编译错误,那么你的代码结构已经捕捉到这个(就像使用 Stage,如上所述),在这种情况下你需要覆盖父级 class 的 touchDown 实现() 做你需要的。