哦,好了……经过将近一天的努力,终于找到了……。我正在使用scene2d。
我的问题是这个,我有一个名为“ Tile”的类,该类扩展了Image类(扩展了小部件)并在其中具有128x128大小的纹理,但是当我尝试将其添加到表(小部件组)中时,磁贴消失了。
编辑:我只是在桌子上进行了尺寸检查,并验证了在桌子内部添加了一个128x128大小的图块后,桌子以0x0的大小显示自己的情况……这里可能有问题吗?
我已经尝试过:
OBS:我奇怪地观察到的一件事是,当我尝试在我的Tile构造函数中使用setDrawable()(进行Texture-> TextureRegion-> TextureRegionDrawable的适当转换)时,我无法以任何方式绘制它,我只是可以通过在构造函数上调用super(Texture)并观察Image(Drawable)构造函数来使其获得我的纹理,我碰巧注意到,在首次设置可绘制对象时,它还是做了其他事情,但第一次。 .. AND ...即使使用super(Texture),在将单元格添加到表中时也不会显示...也许问题出在这里?我不知道...
我的问题是:
Edit2:根据要求,以下是相关代码:
public class Tile extends Image{
// Tiles
private Texture unselected;
private Texture selected;
// InputListener for detecting mouse over
private class MouseOver extends InputListener{
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
setDrawable(new TextureRegionDrawable(new TextureRegion(selected)));
}
}
private class MouseOut extends InputListener{
public void exit(InputEvent event, float x, float y, int pointer, Actor fromActor) {
setDrawable(new TextureRegionDrawable(new TextureRegion(unselected)));
}
}
public Tile(){
super(TextureFactory.unselectedTile());
unselected = TextureFactory.unselectedTile();
selected = TextureFactory.selectedTile();
this.addListener(new MouseOver());
this.addListener(new MouseOut());
}
}
Tile具有一个侦听器,当我将其放在鼠标上时,它会更改其纹理。我删除了这些监听器进行测试,并且错误仍在发生,所以...不是他们。
实现Tile的屏幕(有些内容已注释,因为我希望那样使用它...)
public class CombatScreen extends AbstractScreen{
private Table board;
public CombatScreen(SpaceGameMain game, int boardSize) {
// Passing game to super class and getting class name for tracking
super(game);
this.className = this.getClass().getSimpleName();
// Creating tile board
board = new Table();
/*
for(int i = 0; i < boardSize; i++)
{
for(int j = 0; j < boardSize; j++){
board.add(new Tile());
}
board.row();
}
*/
}
@Override
public void show(){
super.show();
board.add(new Tile());
mainStage.addActor(board);
}
public void resize(int width, int height){
super.resize(width, height);
board.setPosition((Gdx.graphics.getWidth() - Tile.width)/2, (Gdx.graphics.getHeight() - Tile.height)/2);
}
}
该表格设置在屏幕中间以进行测试。
在badlogic论坛上的Tanmay和NateS的帮助下找到了解决方案,他们指导我进一步了解TableLayout。
发生的情况是,在这种情况下,子代的原始大小不会影响“木板”的布局。您需要做的是使用TableLayout设置子项的大小(而不是prefSize),因此工作代码如下所示:
board.add(new Tile()).size(128, 128);
就是这样,对如何使用表格有些简单的误解。
谢谢你们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句