gpt4 book ai didi

java - (如何设置)/(看不到)Libgdx 文本字段上的光标?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:30 25 4
gpt4 key购买 nike

我尝试创建一个可绘制对象(ninepatch)并在 textfieldstyle 中完成此操作

greenTextFieldStyle.cursor = getSkin().getDrawable("textFieldCursor1");

但是我看不到任何光标...

这是当前光标图像,我也试过1 * 20图像没有成功。

It's really small

它基本上是一个 3 * 3 的图像,中间有一个 + 并指向外面的 9-patch 。

最佳答案

使用 getSkin().newDrawable("textFieldCursor1",Color.green) 并为其添加最小宽度 greenTextFieldStyle.cursor.setMinWidth(2f);

这里有一个包含“selectionframe”的完整皮肤:

Skin skin = new Skin();
skin.add(
"background",
new NinePatch(this.game.manager.get("hud/ninepatchframe.png",
Texture.class), 5, 5, 5, 5));
skin.add("cursor", this.game.manager.get("data/cursor.png"));

TextFieldStyle tStyle = new TextFieldStyle();
tStyle.font = getDefaultFont(25); //here i get the font
tStyle.fontColor = Color.BLACK;
tStyle.background = skin.getDrawable("background");
tStyle.cursor = skin.newDrawable("cursor", Color.GREEN);
tStyle.cursor.setMinWidth(2f);
tStyle.selection = skin.newDrawable("background", 0.5f, 0.5f, 0.5f,
0.5f);

this.nameField = new TextField("enter name here", tStyle);

这里是我如何获得位图字体的。我正在使用 extansion from libgdx.ttf 创建它。查看如何添加本地文件的链接。

这里是代码如何使用它:

public BitmapFont getDefaultFont(int size) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
Gdx.files.internal("fonts/font.ttf"));
defaultFont = generator.generateFont(size + 5); //some offset
return defaultFont;
}

关于java - (如何设置)/(看不到)Libgdx 文本字段上的光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21313575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com