LibGdx中的布局小部件“容器"有问题 [英] Having problems with the layout widget 'Container' in LibGdx
问题描述
我正在为自己的游戏构建菜单,但被卡住了.
当我放置具有功能的容器,然后将setFillParent
设置为true
的按钮添加到容器中,按钮的位置与容器的位置不同.
I'm building a menu for my game and I'm stuck.
When I position a Container with it's setPosition
function and add a Button to the container with setFillParent
set to true
the button's position isn't set to the same position as the container.
按钮大小与容器的大小匹配,但是其位置错误.当我不将setFillParent
设置为true
时,按钮在容器中的位置正确,但是大小错误.
The button size matches the size of the Container but its position is wrong. When I don't set setFillParent
to true
the position of the button within the container is right but the size is wrong.
这是代码,非常简单:
Container container = new Container(exitButton);
exitButton.setFillParent(true/false);
这是说明此问题的图片,左侧图片的setFillParent
设置为true
而正确的图像则没有.
Here is an image that ilustrate this, left image has setFillParent
set to true
and the right image does not.
图像上的绿色突出显示为container
,[X]图像为exitButton
.
The green hightlight on the image is the container
, the [X] image is the exitButton
.
推荐答案
好吧,我想通了,在设置容器的大小和位置之前调用container.fill()
可以解决问题.不知道为什么,但是它解决了.
Ok, I figured it out, calling container.fill()
before setting the containers size and position somehow solves the problem. No idea why, but it solves it.
这篇关于LibGdx中的布局小部件“容器"有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!