Having problems with the layout widget 'Container' in LibGdx

浪尽此生 提交于 2020-01-17 06:15:41

问题


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.

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.

Here is the code, pretty simple:

Container container = new Container(exitButton);

exitButton.setFillParent(true/false);

Here is an image that ilustrate this, left image has setFillParent set to true and the right image does not.

The green hightlight on the image is the container, the [X] image is the exitButton.


回答1:


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.



来源:https://stackoverflow.com/questions/43958162/having-problems-with-the-layout-widget-container-in-libgdx

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