Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx: IOS on screen keyboard not firing events consistently

I am having trouble with InputProcessor only on my IOS build. This code works for Desktop and Android builds but not iOS.

Basically, I need to catch an event anytime the user types on the onscreen keyboard. But in iOS I only see my println for keyTyped intermittantly and only when i type on the on screen keyboard fast. All the other touches just show a new line in the console, I am not sure where this new line output is originating from.

The issue seems to stem from however iOS sends events back to my application and how LibGDX InputProcessor receives them. I have tried creating my own object that extends TextField and implements InputProcessor then set the instance of that object as the inputProcessor but i get the same result. If i touch anywhere on the screen that is not the iOS onscreen keyboard i get events firing consistently.

This is what the iOS console output looks like this when i type very fast, if i type slow the println never shows up:

game name field key typed!


game name field key typed!






game name field key typed!

Doing the same thing on an android device (nexus 7) yields the following (which is what I would expect):

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!

here is my code:

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 version: 1.9.6 RoboVM (MobiDevelop) version : 2.3.1

I guess i can always roll my own on-screen keyboard...

like image 903
Brian G Avatar asked Jun 01 '17 03:06

Brian G


1 Answers

Just wanted to follow up incase anyone finds themselves here in the future. I ended up creating my own on screen keyboard, I could not get the events to work consistently in iOS.

If anyone has anything they want to add in the future i will check in to accept the answer.

like image 87
Brian G Avatar answered Nov 14 '22 12:11

Brian G