2014-01-23 43 views
3

我試圖創建一個可繪製(ninepatch)和textfieldstyle做到了這一點(如何設置)/(無法看到)光標在Libgdx中的Textfield?

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

但我看不到任何光標...

這是當前光標的形象,我也試着1 * 20圖像沒有成功。

It's really small

它基本上是一個3×3的圖像,在中間和外點的ninepatch A +。

回答

3

使用getSkin().newDrawable("textFieldCursor1",Color.green)並添加最小寬度它greenTextFieldStyle.cursor.setMinWidth(2f);

這裏compleat皮膚包容 「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創建它。 查看鏈接如何添加nativ文件。

下面的代碼如何使用它:

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

感謝,對setMinWidth(2F);爲我做了!此外,我可以看到你正在使用某種方法來獲取大小的默認字體,你如何設置bitmapfont的大小? – thetheodor

+0

將其添加到答案中。我正在使用'gdx-freetype'擴展。代碼可能是過時的。我的遊戲正在使用9.7.x,如果我記得正確的話 – BennX

+0

謝謝,請檢查一下!你能幫助回答這個問題嗎? http://stackoverflow.com/questions/21318030/cant-draw-a-ninepatch-image-and-stage-at-the-same-time – thetheodor