2017-05-27 64 views
0

我正在使用TextButton在我的游戏中创建对话框泡泡效果。 我已经创建了九个补丁文件,如图片 enter image description here 一切似乎都很好,直到我尝试使用此泡泡.9与LibGDX,TextButton不能正确基于文本高度伸展。Libgdx九个补丁文本按钮高度问题

enter image description here

enter image description here

你可以看到一个文本多线延伸TextButton高度,但不正确。

下面是代码

装入位图字体

FileHandleResolver resolver = new InternalFileHandleResolver(); 
assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); 
assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver)); 
FreetypeFontLoader.FreeTypeFontLoaderParameter dialogFont = new FreetypeFontLoader.FreeTypeFontLoaderParameter(); 
dialogFont.fontFileName = Conf.ASSET_FONT; 
dialogFont.fontParameters.size = 8; 

初始化TextButtonStyle

NinePatch patch = atlas.createPatch("bubble"); 
NinePatchDrawable dialogBoxPatch = new NinePatchDrawable(patch); 
buttonStyle = new TextButton.TextButtonStyle(); 
buttonStyle.up = dialogBoxPatch; 
buttonStyle.down = dialogBoxPatch; 
buttonStyle.checked = dialogBoxPatch; 
buttonStyle.over = dialogBoxPatch; 
buttonStyle.font = dialogFont; 
buttonStyle.fontColor = Color.BLACK; 

实际渲染

dialogBox = new TextButton("some\ntext", buttonStyle); 
dialogBox.draw(batch, 1); 

是否有人看到WH在问题是?

回答

1

我终于找到了问题。 我决定用另一种字体测试ninepatch,它的功能就像一个魅力。为了理解发生了什么,我打开了两个字体glyphrstudio。看来有问题的字体设计不正确。

坏字体

enter image description here

好字体

enter image description here

宥可以看出,基线和大写高度未正确设置好的就坏了字体。

我希望这会帮助其他人面临同样的问题。