简体   繁体   English

如何更改LibGdx的CheckBox图像的大小?

[英]How can I change the size of the CheckBox image of LibGdx?

I'm using the skin from libgdx tests: uiskin.json. 我正在使用libgdx测试中的皮肤:uiskin.json。

For some reason the checkbox is displayed much smaller as fe in badlogic/gdx/tests/MipMapTest.java What does the size of the Checkbox depend on? 出于某种原因,在badlogic / gdx / tests / MipMapTest.java中,该复选框显示得比fe小得多。Checkbox的大小取决于什么? the camera's resolution? 相机的分辨率? Or is there a way to set it manually? 还是有一种手动设置的方法?

Helper.RESOLUTION_WIDTH = 800 and Helper.RESOLUTION_WIDTH = 800并且

Helper.RESOLUTION_HEIGHT = 1280 Helper.RESOLUTION_HEIGHT = 1280

@Override
public void show() {

    skin = new Skin(Gdx.files.internal("skins/uiskin.json"));
    cam = new OrthographicCamera(Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT);
    cam.position.set(Helper.RESOLUTION_WIDTH / 2, Helper.RESOLUTION_HEIGHT / 2, 0); 
    stage = new Stage(Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT, true);
    stage.setCamera(cam);

    CheckBox checkBox1 = new CheckBox("", skin);
    checkBox1.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.setScreen(new WinScreen2a(game));
        }
    });
    CheckBox checkBox2 = new CheckBox("", skin);
    checkBox2.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.setScreen(new WinScreen2b(game));
        }
    });

    Window window = new Window("Dialog", skin);
    window.debug();
    window.setPosition(Helper.RESOLUTION_WIDTH/2 - 375, 10);
    window.setSize(750, 350);

    table.add(checkBox1).left();
    table.getCells().get(0).size(200, 100);
    table.add(option1).width(500).height(100).pad(10f);
    table.row();

    table.add(checkBox2).left();
    table.getCells().get(2).size(200, 100);
    table.add(option2).width(500).height(100).pad(10f);
    table.row();

    window.add(table).top().left();
    stage.addActor(window);

This changes the checkbox image size, but I noticed that the click detection is not accurate then. 这会更改复选框图像的大小,但是我注意到单击检测不正确。 Couldn't change that with setting the bounds of the box, but maybe there is still some way yet to be discovered. 不能通过设置框的边界来改变它,但是也许还有一些方法尚待发现。

CheckBox cb = new CheckBox(" Label text", xxx.getDefaultSkin());
// Changes the checkbox image size
cb.getImageCell().height(50);
cb.getImageCell().width(50);
// Change the text size accordingly
cb.getLabel().setFontScale(0.6f, 0.6f);

My thoughs though are that it may be nicer to create a custom component for this => Create a class that extends Actor . 不过我的想法是,为此=>创建一个扩展Actor的类可能会更好。 The class wraps an image button with a label. 该类用标签包装图像按钮。 Then add helper methods to easily modify the component as needed. 然后添加帮助程序方法,以根据需要轻松修改组件。 This way I have had success in creating complex easily reusable components that look neat. 这样,我就成功地创建了看起来很简洁的复杂易重用组件。

You need to set image scaling type. 您需要设置图像缩放比例类型。 Default is none. 默认为无。

CheckBox soundCB = new CheckBox("Sound", uiskin);
soundCB.getImage().setScaling(Scaling.fill);
soundCB.getImageCell().size(GameConfig.WIDTH/6);
soundCB.left().pad(PAD);
soundCB.getLabelCell().pad(PAD);
//...
content.add(soundCB).width(GameConfig.WIDTH/1.5f).row(); //add to table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM