Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WidgetGroup而不是Table作为ScrollPane小部件的libGDX ScrollPane?_Libgdx_Widget_Scrollpane - Fatal编程技术网

使用WidgetGroup而不是Table作为ScrollPane小部件的libGDX ScrollPane?

使用WidgetGroup而不是Table作为ScrollPane小部件的libGDX ScrollPane?,libgdx,widget,scrollpane,Libgdx,Widget,Scrollpane,据我所知,通过使用一个表作为ScrollPane小部件,ScrollPane可以添加多个小部件(这是在libGDX repo中的ScrollPane测试中完成的) 我希望实现类似的功能,但希望在ScrollPane小部件中有许多参与者的绝对定位,而不是使用表格作为ScrollPane小部件提供的表格定位 我最终得到了这段不起作用的代码,但根据libgdxjavadoc,它应该起作用,我不知道为什么它不起作用 stage = getStage(); // Scroll pane outer co

据我所知,通过使用一个表作为ScrollPane小部件,ScrollPane可以添加多个小部件(这是在libGDX repo中的ScrollPane测试中完成的)

我希望实现类似的功能,但希望在ScrollPane小部件中有许多参与者的绝对定位,而不是使用表格作为ScrollPane小部件提供的表格定位

我最终得到了这段不起作用的代码,但根据libgdxjavadoc,它应该起作用,我不知道为什么它不起作用

stage = getStage();

// Scroll pane outer container
Container<ScrollPane> container = new Container<ScrollPane>();
container.setSize(Game.getWidth(), Game.getHeight());

// Scroll pane inner container
WidgetGroup widgetGroup = new WidgetGroup();
widgetGroup.setFillParent(true);
widgetGroup.addActor(new Image(MAP_TEXTURE_ATLAS.findRegion("map")));

// Scroll pane
ScrollPane scrollPane = new ScrollPane(widgetGroup);
container.setActor(scrollPane);

stage.addActor(container);
stage=getStage();
//滚动窗格外容器
容器=新容器();
container.setSize(Game.getWidth(),Game.getHeight());
//滚动窗格内容器
WidgetGroup WidgetGroup=新的WidgetGroup();
widgetGroup.setFillParent(true);
addActor(新图像(MAP_TEXTURE_ATLAS.findRegion(“MAP”));
//滚动窗格
ScrollPane ScrollPane=新的ScrollPane(widgetGroup);
容器.setActor(滚动窗格);
stage.addActor(容器);
屏幕上根本没有显示任何内容

但是,它可以使用下面的代码(这显然不是我想要的,因为ScrollPane小部件是一个只能有一个参与者的容器)

//滚动窗格外部容器
容器=新容器();
container.setSize(Match3.getWidth(),Match3.getHeight());
//滚动窗格内容器
Container container2=新容器();
集装箱2.退堆区(新的纹理区域(地图纹理区域(“地图”));
//滚动窗格
ScrollPane ScrollPane=新的滚动窗格(container2);
容器.setActor(滚动窗格);
stage.addActor(容器);
是否有一种方法可以将WidgetGroup与ScrollPane一起使用,或者如何实现所需的功能

谢谢

可接受答案的替代实施

在阅读了接受的答案后,我决定创建自己的类,实现如下

// Scroll pane outer container
Container<ScrollPane> container = new Container<ScrollPane>();
container.setSize(Match3.getWidth(), Match3.getHeight());

class ScrollWidget extends WidgetGroup {

  private float prefHeight;
  private float prefWidth;

  public ScrollWidget(Image image) {

    prefHeight = image.getHeight();
    prefWidth = image.getWidth();

    addActor(image);
  }

  @Override
  public float getPrefHeight() {

    return prefHeight;
  }

  @Override
  public float getPrefWidth() {

    return prefWidth;
  }
}

ScrollWidget scrollWidget = new ScrollWidget(
    new Image(MAP_TEXTURE_ATLAS.findRegion("map"))
);

// Scroll pane
ScrollPane scrollPane = new ScrollPane(scrollWidget);
scrollPane.setOverscroll(false, false);

scrollPane.layout();
scrollPane.updateVisualScroll();
scrollPane.setScrollY(scrollPane.getMaxY());

container.setActor(scrollPane);

stage.addActor(container);
//滚动窗格外部容器
容器=新容器();
container.setSize(Match3.getWidth(),Match3.getHeight());
类ScrollWidget扩展了WidgetGroup{
私人浮动高度;
私有浮动宽度;
公共滚动窗口小部件(图像){
prefHeight=image.getHeight();
prefWidth=image.getWidth();
加法器(图像);
}
@凌驾
公共浮动高度(){
返回高度;
}
@凌驾
公共浮点getPrefWidth(){
返回宽度;
}
}
ScrollWidget ScrollWidget=新的ScrollWidget(
新图像(地图、纹理、图集、findRegion(“地图”))
);
//滚动窗格
ScrollPane ScrollPane=新的ScrollPane(scrollWidget);
scrollPane.setOverscroll(false,false);
scrollPane.layout();
scrollPane.updateVisualScroll();
scrollPane.setScroly(scrollPane.getMaxY());
容器.setActor(滚动窗格);
stage.addActor(容器);

使用WidgetGroup时,您必须自己设置大小。图像参与者不知道首选宽度/高度应该是多少,将默认为0

未经测试的代码,但我自己也使用类似的代码:

Stage stage = new Stage();
WidgetGroup group = new WidgetGroup();
Scrollpane scrollPane = new ScrollPane(group);
scrollpane.setBounds(0,0,screenWidth,screenHeight);
group.setBounds(0,0,totalWidth,totalHeight);
Image image = new Image(texture);
image.setBounds(0,0,imageWidth,imageHeight);
group.addActor(image);
stage.addActor(scrollPane);

谢谢,这就是问题所在!我对我的问题进行了编辑,添加了一个类似于您解决问题的方法的解决方案。
Stage stage = new Stage();
WidgetGroup group = new WidgetGroup();
Scrollpane scrollPane = new ScrollPane(group);
scrollpane.setBounds(0,0,screenWidth,screenHeight);
group.setBounds(0,0,totalWidth,totalHeight);
Image image = new Image(texture);
image.setBounds(0,0,imageWidth,imageHeight);
group.addActor(image);
stage.addActor(scrollPane);