2017-06-01 68 views
6

我只在IOS構建中遇到InputProcessor問題。此代碼適用於Desktop和Android版本,但不適用於iOS。libgdx:屏幕鍵盤上的IOS始終無法觸發事件

基本上,我需要在用戶鍵入屏幕鍵盤時隨時捕捉事件。但是在iOS中,我只能看到我的printType爲keyTyped,並且只能在屏幕快速鍵盤上輸入。所有其他觸摸只是在控制檯中顯示一個新行,我不確定這個新行輸出源自哪裏。

這個問題似乎源於iOS發送事件回到我的應用程序以及LibGDX InputProcessor如何接收它們。我已經嘗試創建自己的擴展TextField並實現InputProcessor的對象,然後將該對象的實例設置爲inputProcessor,但我得到了相同的結果。如果我觸摸不在iOS屏幕鍵盤上的任何位置,我會一直觸發事件。

這是iOS的控制檯輸出看起來像這樣當我鍵入速度非常快,如果我型緩中的println一直沒有出現:

game name field key typed! 


game name field key typed! 






game name field key typed! 

做一個Android設備上同樣的事情(的Nexus 7)收益率以下(這是我所期望的):

I/System.out: game name field key down! 
I/System.out: game name field key up! 
I/System.out: game name field key typed! 
I/System.out: game name field key down! 
I/System.out: game name field key up! 
I/System.out: game name field key typed! 
I/System.out: game name field key down! 
I/System.out: game name field key up! 
I/System.out: game name field key typed! 

這裏是我的代碼:

public class AccountScreen implements Screen { 


final PieTherapy game; 
private Stage stage; 

private TextField gameNameField; 

public AccountScreen(final PieTherapy game) { 
    this.game = game; 
    initialize(); 
} 

private void initialize() { 

    Viewport vp = new StretchViewport(PieTherapy.WORLD_WIDTH, PieTherapy.WORLD_HEIGHT, game.cam); 
    stage = new Stage(vp); 

    Gdx.input.setInputProcessor(stage); 

    TextField.TextFieldStyle tfs = new TextField.TextFieldStyle(); 
    tfs.font = game.fontTitle; 
    tfs.fontColor = Color.WHITE; 
    tfs.background = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/textline.png", Texture.class))); 
    tfs.focusedBackground = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/textline-selected.png", Texture.class))); 
    tfs.cursor = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/cursor.png", Texture.class))); 

    gameNameField = new TextField("", tfs); 
    gameNameField.setWidth(PieTherapy.WORLD_WIDTH * .80f); 
    gameNameField.setFocusTraversal(true); 
    gameNameField.setPosition(PieTherapy.WORLD_WIDTH *.05f, game.WORLD_HEIGHT * .68f); 
    // see if the player information has already been entered (edit mode) 
    gameNameField.setText(game.primaryPlayer.gameName); 
    gameNameField.addListener(new InputListener(){ 
     @Override 
     public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
      System.out.println("game name field touch up!"); 
     } 
     @Override 
     public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
      System.out.println("game name field touch down!"); 
      return true; 
     } 

     @Override 
     public boolean keyDown(InputEvent event, int keycode) { 
      System.out.println("game name field key down!"); 
      return super.keyDown(event, keycode); 
     } 

     @Override 
     public boolean keyUp(InputEvent event, int keycode) { 
      System.out.println("game name field key up!"); 
      return super.keyUp(event, keycode); 
     } 

     @Override 
     public boolean keyTyped(InputEvent event, char character) { 
      System.out.println("game name field key typed!"); 
      return super.keyTyped(event, character); 
     } 
    }); 

    gameNameField.getOnscreenKeyboard().show(true); 
    gameNameField.setCursorPosition(gameNameField.getText().length()); 

    stage.addActor(gameNameField); 

    stage.setKeyboardFocus(gameNameField); 
} 

@Override 
public void show() { 

} 

@Override 
public void render(float delta) { 
    Gdx.gl.glClearColor(0, 0, 0f, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    game.batch.begin(); 
    game.font.draw(game.batch, "Your name in the game! You can stick with the\nautomatically generated" + 
        "one or change to your own.\n Red: name is not available, " + 
        "green: available.", 
      PieTherapy.WORLD_WIDTH *.36f, 
      PieTherapy.WORLD_HEIGHT *.93f); 

    game.batch.end(); 

    update(delta); 
} 

private void update(float delta) { 

    stage.act(delta); 

    stage.draw(); 

    game.batch.begin(); 

    game.batch.end(); 

} 

@Override 
public void resize(int width, int height) { 

} 

@Override 
public void pause() { 

} 

@Override 
public void resume() { 

} 

@Override 
public void hide() { 

} 

@Override 
public void dispose() { 

} 
} 

LibGDX版本:1.9.6 RoboVM(MobiDevelop)版本:2.3.1

我想我總是可以推出自己的屏幕鍵盤...

回答

2

只是想跟進櫃面任何人在這裏找到自己在將來。我最終創建了我自己的屏幕鍵盤,我無法讓事件在iOS中始終如一地工作。

如果任何人有任何他們想在未來添加我會檢查接受答案。