Jay*_*ama 6 java android scrollpane libgdx
情况:
首先,我是LibGDX的新手.
我正在制作一个游戏,玩家可以在屏幕上看到所有成就,所以我正在使用ScrollPane.
成就以弹出形式显示(见下图).成就列表将在这些红线内.
截图:

问题:
问题是:当我将小部件添加到ScrollPane时,屏幕仅显示黑屏.
奇怪的是:
- 当我拖动 ScrollPane时,一切都正确呈现.
- 但是当我放手时,屏幕再次变黑.
我做了什么:
- 我发现我放入 ScrollPane参数的任何演员(不仅仅是桌子)都会导致黑屏.
- 如果我将它设置为 null,它可以正常工作.
码:
public void show() {
stage = new Stage();
roomScreenUI = new RoomScreenUI();
roomScreenUI.setName("RoomScreenUI");
stage.addActor(roomScreenUI);
roomScreenButton = new RoomScreenButton[5];
for(int i=0; i<roomScreenButton.length; i++){
roomScreenButton[i] = new RoomScreenButton(i+1, roomScreenUI.getScaleFactor());
roomScreenButton[i].setName("RoomScreenButton");
stage.addActor(roomScreenButton[i]);
}
roomScreenAchievementUI = new RoomScreenAchievementUI(roomScreenUI.getScaleFactor());
roomScreenAchievementUI.setName("RoomScreenAchievementUI");
stage.addActor(roomScreenAchievementUI);
//----------------THE PROBLEM LIES HERE----------------//
achievementContainer = new Table();
scrollPane = new ScrollPane(achievementContainer);
// scrollPane = new ScrollPane(null); <-- If I replace it with this line, it works fine
//----------------THE PROBLEM LIES HERE----------------//
achievementTable = new Table();
achievementTable.setSize(roomScreenAchievementUI.getWidth() * 0.9f, roomScreenAchievementUI.getHeight() * 0.8f);
achievementTable.setPosition(roomScreenAchievementUI.getX() + roomScreenAchievementUI.getWidth() / 2 - achievementTable.getWidth() / 2, roomScreenAchievementUI.getY() + roomScreenAchievementUI.getHeight() * 0.48f - achievementTable.getHeight() / 2);
achievementTable.debug();
achievementTable.add(scrollPane).expand().fill();
achievementTable.setName("AchievementTable");
stage.addActor(achievementTable);
Gdx.input.setInputProcessor(stage);
}
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// ... code omitted ... //
stage.act(delta);
stage.draw();
}
Run Code Online (Sandbox Code Playgroud)
问题:
任何人对发生了什么都有任何想法?
我该如何解决?
先谢谢......
================================================== ================================
更新
================= ================================================== ===============
经过几个小时的实验,我创建了一个更简单的项目,只有一个屏幕和一个演员从头开始:
TestActor.java(这是演员)
Texture texture;
Sprite sprite;
public TestActor(){
// I used the default generated image badlogic.jpg
texture = new Texture(Gdx.files.internal("badlogic.jpg"));
sprite = new Sprite(texture);
}
@Override
public void draw(Batch batch, float alpha){
batch.draw(sprite, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
Run Code Online (Sandbox Code Playgroud)
TestClass.java(这是屏幕)
Stage stage;
ScrollPane scrollPane;
Table outerTable, innerTable;
TestActor testActor;
@Override
public void show() {
stage = new Stage();
testActor = new TestActor();
stage.addActor(testActor);
//---------THE PROBLEM IS STILL HERE---------//
innerTable = new Table();
scrollPane = new ScrollPane(innerTable); // change it to null, it works
//---------THE PROBLEM IS STILL HERE---------//
outerTable = new Table();
outerTable.setPosition(0, 0);
outerTable.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
outerTable.debug();
outerTable.add(scrollPane).fill().expand();
stage.addActor(outerTable);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
Run Code Online (Sandbox Code Playgroud)
我在调试时想出了一些可能是线索的东西:
- 在第一帧,一切都正确呈现.
- 从第二帧开始,屏幕变黑.
这是一个错误吗?
还是我误解了?
任何帮助将不胜感激...
编辑托盘此代码
例子:
public class TestActor extends Widget {
Texture texture;
Sprite sprite;
public TestActor(){
// I used the default generated image badlogic.jpg
texture = new Texture(Gdx.files.internal("badlogic.jpg"));
sprite = new Sprite(texture);
}
@Override
public void draw(Batch batch, float parentAlpha){
Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
batch.draw(sprite, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
Run Code Online (Sandbox Code Playgroud)
}