LibGDX scale a slider, HOW?

*爱你&永不变心* 提交于 2019-12-12 03:57:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!