我有libgdx的问题。我正在制作程序,有盒子输入,然后你可以选择algorhytm将它们分类到卡车里。
我有移除框的问题。在我使用此代码之后,应删除所有actor,即Textures(框)。
for(Actor actor : stage.getActors()){
if(actor.getClass() == Textures.class){
actor.remove();
}
}
排序算法运行良好,所有箱子都在卡车上,但它不会删除一些旧箱子。
然后我尝试使用actor.getName()
删除它们。结果相同。还有代码whitch创建actor:
for(Actor actor : stage.getActors()){
if(actor.getName()!=null){
if(actor.getName().equals("shape")){
actor.remove();
}
}
}
//create actors
for (ShapeMeasurments sh:shapes) {
Textures textures = new Textures((sh.getX()*1.45f+30),sh.getY()*1.45f,sh.getWidth()*1.45f,
sh.getHeight()*1.45f,sh.getMaterial());
textures.setName("shape");
stage.addActor(textures);
}
答案 0 :(得分:1)
我发现了一个问题。 actor.remove()
是foreach循环中的问题。删除foreach循环中的actor可能会导致问题。那么我使用actor.addAction(Actions.removeActor());
并且它有效。这在second answer
不使用if(actor.getClass() == Textures.class)
比较类不是一件容易的事,你应该使用actor.setName()
和actor.getName()
。