Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial value of TextBox does not appear #318

Open
f3rn4nd0-c354r opened this issue Apr 12, 2024 · 0 comments
Open

Initial value of TextBox does not appear #318

f3rn4nd0-c354r opened this issue Apr 12, 2024 · 0 comments

Comments

@f3rn4nd0-c354r
Copy link

f3rn4nd0-c354r commented Apr 12, 2024

Hello,

I'm starting out with Mini2Dx.
I'm creating this UI, where the player has to set some numbers, but I wanted to have a default value. So I set it. But it doesn't appear. It only appears in the TextBox if I insert another character (while the game is running).

image

This is what I'm trying:

        // text box
        textBox = new TextBox(20, 50, 50, 20);
        textBox.setVisibility(Visibility.VISIBLE);
        textBox.setValue("5");

Full example (this is the only file I changed from a generated game.

MyMini2DxGame.java

package com.mystudio.gamename;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.ClasspathFileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.graphics.Texture;
import org.mini2Dx.core.assets.FallbackFileHandleResolver;
import org.mini2Dx.core.game.BasicGame;
import org.mini2Dx.core.graphics.Graphics;
import org.mini2Dx.ui.UiContainer;
import org.mini2Dx.ui.UiThemeLoader;
import org.mini2Dx.ui.element.TextBox;
import org.mini2Dx.ui.element.Visibility;
import org.mini2Dx.ui.style.UiTheme;

public class MyMini2DxGame extends BasicGame {
	public static final String GAME_IDENTIFIER = "com.mystudio.gamename";

    private AssetManager assetManager;
	private Texture texture;
    private UiContainer uiContainer;
    private TextBox textBox;
	@Override
    public void initialise() {
        // UI
        //Create fallback file resolver, so we can use the default mini2Dx-ui theme
        FileHandleResolver fileHandleResolver = new FallbackFileHandleResolver(new ClasspathFileHandleResolver(),
                                                                               new InternalFileHandleResolver());
        //Create asset manager for loading resources
        assetManager = new AssetManager(fileHandleResolver);
        //Add mini2Dx-ui theme loader
        assetManager.setLoader(UiTheme.class, new UiThemeLoader(fileHandleResolver));
        //Load default theme
        assetManager.load(UiTheme.DEFAULT_THEME_FILENAME, UiTheme.class);
        uiContainer = new UiContainer(this, assetManager);
        Gdx.input.setInputProcessor(uiContainer);

    	texture = new Texture("mini2Dx.png");
        // text box
        textBox = new TextBox(20, 50, 50, 20);
        textBox.setVisibility(Visibility.VISIBLE);
        textBox.setValue("5");

        uiContainer.add(textBox);
    }
    
    @Override
    public void update(float delta) {
        // UI
        if(!assetManager.update()) {
            //Wait for asset manager to finish loading assets
            return;
        }
        if(!UiContainer.isThemeApplied()) {
            UiContainer.setTheme(assetManager.get(UiTheme.DEFAULT_THEME_FILENAME, UiTheme.class));
        }
        uiContainer.update(delta);
    }
    
    @Override
    public void interpolate(float alpha) {
        uiContainer.interpolate(alpha);
    }
    
    @Override
    public void render(Graphics g) {
		g.drawTexture(texture, 0f, 0f);
        uiContainer.render(g);
    }
}

Full project:
mini2dxtest.zip

Thanks in advance for any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant