gpt4 book ai didi

java - Libgdx场景2D : Add table in seperate class

转载 作者:行者123 更新时间:2023-12-01 11:16:26 26 4
gpt4 key购买 nike

任何人都可以给我一个将表格和表格中的 Actor 添加到另一个类的舞台的示例吗?

最佳答案

您可以通过舞台作为引用或交出 table

public class TableHandler {

public Table getAwesomeTable()
{
Table table = new Table();
//.. do stuff with table

//return table
return table;
}

public static Table getTableWithoutInstancingThisClass()
{
Table table = new Table();
//.. do stuff with table

//return table
return table;
}

public static void handMeTheStageToAlterIt(Stage stage)
{
//stage is passed as reference,
// as long as you don't give it a new Stage object you can alter it.
stage.addActor(...);
}
}

public class MyScreen implements Screen {
Stage stage;


@Override
public void show() {
stage = new Stage();

stage.addActor(TableHandler.getTableWithoutInstancingThisClass());

TableHandler.handMeStageToAlterIt(stage);


//instance tableHandler to get none static members.
TableHandler tableHandler = new TableHandler();
stage.addActor(tableHandler.getAwesomeTable());
}

}

关于java - Libgdx场景2D : Add table in seperate class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com