問題描述
如何從平鋪中刪除對象? (How do I remove an object from tiled?)
假設我在 Tiled 的對象層中放置了一個對象。編寫代碼時應該如何將這些對象彼此分開?(示例:我們與硬幣的主體相撞,不再需要主體)
參考解法
方法 1:
For the tile layer just set cell to null.
//Rectangle tmp = new Rectangle();
if (colideTileLayer.getCell(ix, iy) != null) {
tmp.set(ix * tileWidth, iy * tileHeight, tileWidth, tileHeight);
if (tmp.overlaps(rectangle)) {
colideTileLayer.setCell(ix, iy, null); //THIS IS LINE
GameManager.INSTANCE.incResult();
result = true;
}
}
In case your obstacle is defined in the object layer and visually represented in tile layer recalculate which tiles need to be erased, based on object position.
Than remove an object from object layer, use remove method.
//MapObjects objects = layer.getObjects(); //you read if from object layer
//MapObject object = getColidedObject(); //you need to know what to remove
objects.remove(object); //remove