我有一个问题,我还没有找到解决方案.我正在制作一个小游戏,如果与另一个名为ball的对象相撞,_sballs ArrayList中的对象将被删除.我遇到的问题是,当碰撞发生时,当我尝试从ArrayList中删除对象时,应用程序崩溃.
for(GObject sballgraphic : _sballs){
Coordinates sballcoords = sballgraphic.getCoords();
if(coords.getY() - coords._height > sballcoords.getY() + sballcoords._height && coords.getX() - coords._width > sballcoords.getX() + sballcoords._width){
_sballs.remove(sballgraphic);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,代码将球坐标与所有sballs对象进行比较以检查是否存在碰撞,然后尝试移除sball.
这里有什么问题?:)