Java 在 libgdx 中使用不同大小的相同字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9673086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using the same font with different sizes in libgdx
提问by Rudy_TM
I am using BitmapFonts, LabelStyles and Labels for my texts.
我在文本中使用 BitmapFonts、LabelStyles 和 Labels。
I want to resize some labels, so I use this:
我想调整一些标签的大小,所以我使用这个:
fontType.scale(-.6f);
LabelStyle style = new LabelStyle(fontType, Color.WHITE);
titleLabel = new Label("Points", style);
titleLabel.setColor(Color.RED);
titleLabel.x = 260;
titleLabel.y = 310;
But when I want to resize another label, all the labels containing that font resize (I create a new LabelStyle). So I resize the label instead of the font, but that doesnt solve the problem, because it doesnt resize the label, any idea?
但是当我想调整另一个标签的大小时,所有包含该字体的标签都会调整大小(我创建了一个新的 LabelStyle)。所以我调整标签而不是字体的大小,但这并不能解决问题,因为它没有调整标签的大小,知道吗?
采纳答案by XiaoChuan Yu
You will have to create separate BitmapFonts and LabelStyle for each Label(or groups of Labels) if you want to scale them independently.
如果要独立缩放它们,则必须为每个标签(或标签组)创建单独的 BitmapFonts 和 LabelStyle。
From checking libgdx source code, Labeluses the reference to BitmapFont from LabelStyle and passes it to a BitmapFontCacheused internally; no deep copy is made at any point so they are all using the same BitmapFont you created the LabelStyle with.
通过查看libgdx源代码,Label使用了LabelStyle对BitmapFont的引用,并将其传递给内部使用的BitmapFontCache;任何时候都不会进行深拷贝,因此它们都使用与您创建 LabelStyle 相同的 BitmapFont。
回答by K Hymanson
I am using libgdx 0.9.8 (since this is an old question), and when I created a label as such:
我正在使用 libgdx 0.9.8(因为这是一个老问题),当我创建一个标签时:
lblA = new Label("A", skinA);
I can resize the font of just that label with:
我可以使用以下命令调整该标签的字体大小:
lblA.setFontScale(3);
This doesn't affect other labels I have that were created the same way. I have set some of my labels to font scale (2), and those are OK (not impacted by the (3)). However, I'm finding that styling my label isn't as 'independent'. They need to have their own LabelStyle assigned, otherwise you get the behavior you're stating.
这不会影响我以相同方式创建的其他标签。我已将一些标签设置为字体比例 (2),这些都可以(不受 (3) 影响)。但是,我发现我的标签样式并不是“独立”的。他们需要分配自己的 LabelStyle ,否则你会得到你所陈述的行为。