2016-07-23 70 views
1

添加圖像我有這個表:Libgdx刪除,並從細胞

table.add(image1).size(image1.getWidth(), image1.getHeight()); 
table.add().size(image1.getWidth(), image1.getHeight()).row(); 
table.add().size(image1.getWidth(), image1.getHeight()); 
table.add().size(image1.getWidth(), image1.getHeight()); 

我想,當我點擊空單元格,圖像從細胞中刪除,並添加到單擊的單元格。例如,當我點擊第三個單元格時,從第一個單元格中移除image1並將其添加到第三個單元格中。怎麼辦?

更新2:

我寫了這個代碼,但是當我點擊CELL1,此搜索不會添加表,並添加合適的屏幕上,點擊CELL0不起作用。

Group group = new Group(); 
    group.addActor(image1); 
    group.addActor(image2); 
    group.addActor(image3); 
    root.add(group).size(16, 16); 
    root.add(image4).size(image4.getWidth(), image3.getHeight()).row(); 
    root.add(image5).size(image5.getWidth(), image4.getHeight()); 
    root.add(image6).size(image6.getWidth(), image5.getHeight()); 

    stage.addActor(root); 
    stage.setDebugAll(true); 

    root.getChildren().get(1).addListener(new InputListener(){ 
     @Override 
     public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 
      root.getCells().get(1).clearActor(); 
      root.getCells().get(0).clearActor(); 
      root.getCells().get(0).setActor(image1); 
      group.clear(); 
      group.addActor(image4); 
      group.addActor(image2); 
      group.addActor(image3); 
      root.getCells().get(1).setActor(group); 
      return true; 
     } 
    }); 

    root.getChildren().get(0).addListener(new InputListener(){ 
     @Override 
     public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 
      root.getCells().get(0).clearActor(); 
      root.getCells().get(1).clearActor(); 
      root.getCells().get(1).setActor(image4); 
      group.clear(); 
      group.addActor(image1); 
      group.addActor(image2); 
      group.addActor(image3); 
      root.getCells().get(0).setActor(group); 
      return true; 
     } 
    }); 

回答

0

就個人而言,我會設定,將清除了具有「圖像1」的單元格,然後單擊的單元格指定圖像的每個表格單元格的監聽器。喜歡的東西:

table.getChildren().get(0).addListener(new ClickListener( // .get(0-3) 
    Cell<Table> cell = table.getCell(image1); 
    cell.clearActor(); 
    table.getCells().get(0).setActor(image1);    // .get(0-3) 
)); 

Read libgdx's table api page