问题描述
如何缩放LibGDX中的滑块?
How can I scale a slider in LibGDX?
我正在尝试通过以下方式缩放滑块:
Im trying to scale a slider with:
slider.scale(10); (例如)
slider.scale(10); (for example)
但是当我尝试无法与滑块互动时,导致我认为滑块IST已缩放但呈现正常.我用slider.draw(batch,1);
but when I try that i cant interact with the slider that leads to me thinking that the slider ist scaled but rendered normally. I render it with slider.draw(batch, 1);
有人知道吗?
推荐答案
出于性能原因,大多数scene2d.ui组默认将transform设置为false.
For performance reason most scene2d.ui groups have transform set to false by default.
有关更多详细信息,请检查
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#旋转和缩放
For more detail you can check
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale
如果要缩放,可以使用Container(容器),它对于设置单个小部件的大小和对齐方式很有用.
If you want to scale you can use Container which is useful for setting the size and alignment of a single widget.
@Override
public void create() {
stage=new Stage();
Skin skin=new Skin(Gdx.files.internal("skin/uiskin.json"));
Slider slider=new Slider(0,100,1,false,skin);
Container<Slider> container=new Container<Slider>(slider);
container.setTransform(true); // for enabling scaling and rotation
container.size(100, 60);
container.setOrigin(container.getWidth() / 2, container.getHeight() / 2);
container.setPosition(100,200);
container.setScale(3); //scale according to your requirement
stage.addActor(container);
}
@Override
public void render() {
super.render();
Gdx.gl.glClearColor(1,1,1,1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
stage.act();
}
这篇关于LibGDX缩放滑块,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!