简体   繁体   English

表拉伸中的libgdx按钮

[英]libgdx buttons in table stretching

I want to create buttons in the corners of the screen for the controls of my game. 我想在屏幕的角落创建按钮来控制游戏。 It used to work with just creating a skin, adding that skin to a new ImageButton(skin) and setting the size and position of that button to what is desired. 它过去仅用于创建外观,然后将该外观添加到new ImageButton(skin)并将该按钮的大小和位置设置为所需的值。 I now use box2d and if i now set the size of the button to (1, 1) the height is correct but the width is always about 2/3 of the screen, no matter what i change it to. 我现在使用box2d,如果现在将按钮的大小设置为(1, 1)则高度是正确的,但是宽度始终约为屏幕的2/3,无论我将其更改为什么。 I tried using a table and doing this: 我尝试使用表并执行以下操作:

    table = new Table();
    table.setFillParent(true);
    stage.addActor(table);
    table.setDebug(true);
    table.add(boostButtonn).width(1).height(1).bottom().right();

But I have no clue how to draw it in the corner of the screen, also the button is drawn in the middle of the screen with the correct size using this table, but the skin is stretched out of the button. 但是我不知道如何在屏幕的一角绘制它,也没有使用此表以正确的尺寸在屏幕的中间绘制按钮,但是皮肤从按钮中伸出了。 Viewport width and height are 40,24 respectively 视口的宽度和高度分别为40,24

My skin and button code: 我的皮肤和按钮代码:

Skin skin = new Skin(Gdx.files.internal("skin/flath-earth-ui.json"));
Button bootsButton = new ImageButton(skin);

And then i add it to the table 然后我将其添加到表中

Problem is not in how you align or arrange your widget. 问题不在于您如何对齐或排列小部件。 Problem is why button/widget or even text is stretched and looks blurry. 问题是为什么按钮/小部件甚至文本会被拉伸并显得模糊。

Why stretched ? 为什么要伸展?

Problem is in your resources. 问题出在你的资源上。 Your resources should be compatible with your viewport. 您的资源应与您的视口兼容。 If you're using small viewport then we need your resources(images and fonts) in small size. 如果您使用的是小视口,那么我们需要您的资源(图像和字体)较小。

You're using skin, that used to create Widget . 您正在使用用于创建Widget皮肤。 Skin depends on .json file that contains information about your Widget object and .atlas files having information of your image file. 皮肤取决于.json包含关于您的Widget对象和信息文件.atlas让您的图像文件的信息文件。

You're using 40 as width of viewport then button image that used as drawable should be in range of approx. 您使用40作为视口的宽度,那么用作可绘制对象的按钮图像的范围应在大约。 10. 10。

So what is solution now : 那么现在解决方案是什么:

If you already have all resources ready then use some higher viewport dimension according to your resources else create create resources according to viewport. 如果您已经准备好所有资源,则根据资源使用更高的视口尺寸,否则根据视口创建创建资源。

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

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