Im trying to get my TextField to move on the screen. I want to be able to drag it to a new position on the screen. I´ve been struggling with this for days now and I really cant figure this one out... This is what I´ve done so far:
InputProcessor drag = new InputAdapter() {
@Override
public boolean touchDown(int screenX, int screenY, int pointer,
int button) {
// TODO Auto-generated method stub
return super.touchDown(screenX, screenY, pointer, button);
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer,
int button) {
int x = Gdx.input.getX();
int y = Gdx.input.getY();
textField.setPosition(x, y);
return true;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return super.touchDragged(screenX, screenY, pointer);
}
};
game.inputMultiplexer = new InputMultiplexer();
game.inputMultiplexer.addProcessor(stage);
game.inputMultiplexer.addProcessor(stagePurc);
game.inputMultiplexer.addProcessor(stageText);
game.inputMultiplexer.addProcessor(drag);
Gdx.input.setInputProcessor(game.inputMultiplexer);
Here´s the textfield:
final TextField textField = new TextField(prefs.getString("textField", "Enter name:"), textstyle);
textField.setX(textX);
textField.setY(textY);
textField.setMaxLength(20);
textField.setWidth(textWidth);
textField.setHeight(textHeight);