在 libgdx 方法中,我需要连续执行多个简单文本输入,如下所示:
Gdx.input.getTextInput(input, "Insert Object Type Here", "block", "");
addInputs[0] = input.lastInput();
Gdx.input.getTextInput(input, "Insert x here", "", "");
addInputs[1] = input.lastInput();
Gdx.input.getTextInput(input, "Insert y here", "", "");
addInputs[2] = input.lastInput();
问题是,在我有时间完成第一个 getTextInput 之前,下一个 getTextInput 就会激活,最终导致多个文本框堆叠在一起,并阻止任何输入添加到数组中。我需要一种方法来完全停止代码,然后在文本输入框中按“确定”后再次启动它。
最佳答案
来自wiki :
The input() method will be called when the user enters a text string.
所以你可以将连续的调用放在input
方法中。例如,像这样:
private int inputCalls;
private String[] promptMessages = new String[] {"Insert Object Type Here", "Insert x here", "Insert y here"};
@Override
public void show() {
// ...
// First input call
Gdx.input.getTextInput(new MyTextInputListener(), promptMessages[inputCalls = 0], "block", "");
}
public class MyTextInputListener implements TextInputListener {
@Override
public void input (String text) {
// Keep input value
addInputs[inputCalls++] = text;
if (inputCalls < promptMessages.length) {
// show the subsequent input
Gdx.input.getTextInput(this, promptMessages[inputCalls], "", "");
}
}
@Override
public void canceled () {
Gdx.app.log("Input", "Input canceled");
}
}
请注意,我没有运行此代码,但我希望我建议的解决方案的想法是明确的。
关于java - 多个连续文本输入 Libgdx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35828766/