问题
How can I scale a slider in LibGDX?
Im trying to scale a slider with:
slider.scale(10); (for example)
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);
Has anyone got an idea?
回答1:
For performance reason most scene2d.ui groups have transform set to false by default.
For more detail you can check
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale
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();
}
来源:https://stackoverflow.com/questions/41940854/libgdx-scale-a-slider-how