Java 在scrollpane中的表中放置许多按钮
我在scrollpane中创建了一个包含许多按钮(参与者)的表,如下代码所示:Java 在scrollpane中的表中放置许多按钮,java,libgdx,Java,Libgdx,我在scrollpane中创建了一个包含许多按钮(参与者)的表,如下代码所示: public class ChooseLevel implements Screen { private Stage stage; private Button[][] btnLevel; private Skin skin; private Table table; private ScrollPane scrollPane; private ScrollPaneStyle p
public class ChooseLevel implements Screen {
private Stage stage;
private Button[][] btnLevel;
private Skin skin;
private Table table;
private ScrollPane scrollPane;
private ScrollPaneStyle paneStyle;
@Override
public void show() {
stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
Gdx.input.setInputProcessor(stage);
skin = new Skin(new TextureAtlas(Gdx.files.internal("pack.pack")));
table = new Table();
table.padTop(100f);
btnLevel = new Button[50][3];
for (int row = 0; row < 50; row++) {
for (int col = 0; col < 3; col++) {
btnLevel[row][col] = new Button(skin.getDrawable("up"), skin.getDrawable("down"));
table.add(btnLevel[row][col]).pad(10f);
if (col == 2) table.row().pad(10f);
btnLevel[row][col].addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
for (int row = 0; row < btnLevel.length; row++) {
for (int col = 0; col < btnLevel[0].length; col++) {
if (btnLevel[row][col].isPressed()) {
((Game) Gdx.app.getApplicationListener()).setScreen(new Play());
}
}
}
}
});
}
}
paneStyle = new ScrollPaneStyle(null, null, null, null, skin.getDrawable("unPressed"));
paneStyle.vScrollKnob.setMinWidth(10f);
scrollPane = new ScrollPane(table, paneStyle);
scrollPane.setBounds(0, 0, stage.getWidth(), stage.getHeight());
stage.addActor(scrollPane);
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, false);
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
}
公共类选择器级别实现屏幕{
私人舞台;
专用按钮[][]btnLevel;
私人皮肤;
私人餐桌;
私有滚动窗格;
私人卷轴样式;
@凌驾
公开展览({
stage=newstage(newfitviewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
Gdx.input.setInputProcessor(阶段);
皮肤=新皮肤(新的TextureAtlas(Gdx.files.internal(“pack.pack”));
table=新表();
表1.挂件(100f);
btnLevel=新按钮[50][3];
用于(int行=0;行<50;行++){
for(int col=0;col<3;col++){
btnLevel[row][col]=新按钮(skin.getDrawable(“向上”)、skin.getDrawable(“向下”);
表.添加(BTNL水平[行][列]).pad(10f);
if(col==2)table.row().pad(10f);
btnLevel[row][col].addListener(新建ClickListener()){
@凌驾
公共布尔接地(InputEvent事件、浮点x、浮点y、整数指针、整数按钮){
返回true;
}
@凌驾
公共无效修补(InputEvent事件、浮点x、浮点y、整数指针、整数按钮){
对于(int row=0;row
}
问题是:当我向上或向下滚动时,按钮会监听触摸,然后调用此行((Game)Gdx.app.getApplicationListener()).setScreen(new Play())代码>在我按下特定按钮之前。更改此行:
if(btnLevel[row][col].isPressed())
到
if(btnLevel[row][col].isChecked())