【问题标题】:Libgdx Scene2D: Add table in seperate classLibgdx Scene2D:在单独的类中添加表
【发布时间】:2015-08-02 17:51:16
【问题描述】:

谁能给我一个例子,将表格和表格中的演员添加到另一个班级的舞台?

【问题讨论】:

    标签: java libgdx scene2d


    【解决方案1】:

    您可以通过舞台作为参考或交出桌子

    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());
        }
    
    }
    

    【讨论】:

    • 你应该接受答案并考虑投票;)。
    猜你喜欢
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2013-09-28
    • 2015-12-24
    • 2015-06-24
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多