var action = tiled.registerAction("change",change);
action.text = "金币转换";
var targetTile6
var targetTile7
function change() {
var TileMap = tiled.activeAsset
var layerCount = TileMap.layerCount
var tilesets = TileMap.tilesets
if(!targetTile6) {
for(var i = 0;i<tilesets.length;i++) {
var Tileset = tilesets[i]
if(Tileset.name == "shade_icons") {
targetTile6 = Tileset.tiles[6]
targetTile7 = Tileset.tiles[7]
break
}
}
}
for(var i=0;i<layerCount;i++) {
var TileLayer = TileMap.layerAt(i)
if(TileLayer.isTileLayer) {
if(TileLayer.name == "loot") {
var TileLayerEdit = TileLayer.edit();
var changeTile = false;
for(var col = 0;col<TileLayer.width;col++) {
for(var row = 0;row<TileLayer.height;row++) {
var tile = TileLayer.tileAt(col,row);
if(tile) {
if(tile.id == 3 ) {
changeTile = true;
TileLayerEdit.setTile(col,row,targetTile6);
}else if(tile.id == 4) {
changeTile = true;
TileLayerEdit.setTile(col,row,targetTile7);
}
}
}
}
if(changeTile) {
TileLayerEdit.apply()
tiled.assetSaved(TileMap)
}
break
}
}
}
}
tiled.extendMenu("Edit", [
{ action: "change",},
{ separator: true }
]);
要先明白怎么样导入,导入什么,你的ide里面的所需要修改的和所需要用到的组件、对象叫什么名字,这些对象、组件有何属性、方法。
https://docs.mapeditor.org/en/stable/reference/scripting/#tilelayer
网友评论