0
\$\begingroup\$

Hello I am trying to make login screen for my game, I use TextField's.

1. I am not satisfied with how they look I want it to look like this but simpler - basically to have a white field next to the name of the field.

2. When I run the game it shows just 2 labels, and I can't edit them or anything.

3. Here is my code:

public class FirstTime implements Screen {
private Stage stage;
private UVeggFruit uVeggFruit;
private Music music;
private MenuStage menuStage;
private TextField.TextFieldStyle textFieldStyle;
private OrthographicCamera camera;
private float densityT = 60 * Gdx.graphics.getDensity();
private BitmapFont bitmapFont;


public FirstTime(UVeggFruit uVeggFruit,Music music){
    this.uVeggFruit = uVeggFruit;
    this.music = music;
}



@Override
public void show() {
    stage = new Stage();
    camera = new OrthographicCamera();
    Viewport vp = new StretchViewport(1280, 720, camera);
    stage = new Stage(vp);
    Gdx.input.setInputProcessor(stage);
    ButtonClickListener buttonClickListener = new ButtonClickListener();
    SceneLoader sc = new SceneLoader();
    CompositeItemVO sceneComposites = new CompositeItemVO(sc.loadScene("Login").composite);
    CompositeActor UI = new CompositeActor(sceneComposites, sc.getRm());
    music.setLooping(true);
    music.play();
    stage.addActor(UI);
    UI.getItem("regisbutton").addListener(buttonClickListener);
    UI.getItem("loginbutton").addListener(buttonClickListener);
    FreeTypeFontGenerator FTFG = new FreeTypeFontGenerator(Gdx.files.internal("Karmakooma.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter FTFP = new FreeTypeFontGenerator.FreeTypeFontParameter();
    FTFP.color = Color.WHITE;
    FTFP.size = Math.round(densityT);
    bitmapFont = FTFG.generateFont(FTFP);
    FTFG.dispose();
    textFieldStyle = new TextField.TextFieldStyle();
    textFieldStyle.font = bitmapFont;
    textFieldStyle.fontColor = Color.WHITE;
    TextField username = new TextField("Username",textFieldStyle);
    TextField password = new TextField("Password",textFieldStyle);
    password.setPosition(400, 400);
    username.setPosition(400, 500);
    stage.addActor(username);
    stage.addActor(password);
}

@Override
public void render(float delta) {
    camera.update();
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(delta);
    stage.draw();
}

@Override
public void resize(int width, int height) {
    stage.getViewport().update(width, height, true);
}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {

}

@Override
public void dispose() {
    bitmapFont.dispose();
    music.dispose();

    }
 }

I will be happy if you can answer both of my questions.

\$\endgroup\$
0
\$\begingroup\$

Are you sure that you can't edit them? I believe that the default background color for a TextField is white and it looks like you are setting your font color to white as well. Since the TextFieldStyle.fontColor is also white, I believe that it will have a white cursor.

As for customizing the look of your text fields, rather than creating a TextFieldStyle in code, I would suggest looking into Libgdx's skins. They are kind of like a CSS file for libgdx elements. Here is the wiki page for skins.

The background parameter of the TextFieldStyle class is a drawable so you should be able to achieve the look you want with a ninepatch drawable.

\$\endgroup\$
  • \$\begingroup\$ Yes I am sure I can't, and no the textfield is not white, only the text is white, but I will try with skins, sinde textfieldstyle does not work for me \$\endgroup\$ – nitheism Feb 18 '16 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.