2016-03-06 38 views
0

在libgdx方法我需要在一排預製棒多個簡單的文本輸入,像這樣:多個連續文本輸入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激活之前我有時間完成第一一個以多個文本框堆疊在一起,並阻止任何輸入添加到數組中。我需要一種完全停止代碼的方法,然後在文本輸入框上按「確定」後再次啓動它。

回答

1

wiki:當用戶輸入的文本串

輸入()方法將被調用。

因此,您可以在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"); 
    } 
} 

請注意,我沒有運行此代碼,但是我希望我的建議解決方案的思路是清晰的。

+0

謝謝。出於某種原因,當我進入維基時,這個答案沒有顯示。 – Lukaro707