如何在LibGDX中使ProgressBar正常工作? [英] How do I make a ProgressBar work in LibGDX?
问题描述
我试图了解如何在LibGDX中使用ProgressBar.
I'm trying to understand how to use a ProgressBar in LibGDX.
我已经创建了酒吧,但是我不知道如何使它起作用.我想复制旋钮,以便在60秒内填充条形图(背景线).我知道如何管理时间,但是ProgressBar的类中没有方法用旋钮填充条形图.至少,我还没有看过(或者我可能不知道如何).这是我的代码:
I have created the bar but I don't know how to make it works. I want to duplicate the knob in order to fill the bar(background line) in 60 seconds. I know how to manage about the time, but there is no method in ProgressBar's class to fill the bar with the knob. At least, I haven't seen it (or I don't understand how, possibly). Here is my code:
ProgressBar的代码:
ProgressBar's code:
skin = new Skin();
Pixmap pixmap = new Pixmap(10, 10, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
textureBar = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("barGreen_horizontalMid.png"))));
barStyle = new ProgressBarStyle(skin.newDrawable("white", Color.DARK_GRAY), textureBar);
bar = new ProgressBar(0, 10, 0.5f, false, barStyle);
bar.setPosition(10, 10);
bar.setSize(290, bar.getPrefHeight());
bar.setAnimateDuration(2);
stage.addActor(bar);
我知道我可以使用方法setValue(float)
移动旋钮.但是我想要的是用旋钮的纹理填充条.这是酒吧的屏幕截图和旋钮.
I know that I can move the knob with the method setValue(float)
. But what I want is to fill bar with the knob's texture. Here is a bar's screenshot and the knob.
有人可以帮助我了解这一点吗?预先感谢.
Can anyone help me to understand this? Thanks in advance.
推荐答案
我遇到了同样的问题,最后发现了.
I was having the same problem, and finally found out.
您必须为 knobBefore 属性设置样式才能实现所需的功能. 试试这个:
You have to set a style for the knobBefore attribute to achieve what you want. Try this:
barStyle = new ProgressBarStyle(skin.newDrawable("white", Color.DARK_GRAY), textureBar);
barStyle.knobBefore = barStyle.knob;
bar = new ProgressBar(0, 10, 0.5f, false, barStyle);
希望这会有所帮助!
这篇关于如何在LibGDX中使ProgressBar正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!