Adding plugins
This commit is contained in:
parent
bafdaacfb9
commit
125d264454
3 changed files with 114 additions and 1 deletions
39
random-object-placer.js
Normal file
39
random-object-placer.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
tiled.registerTool("RandomObjectPlacer", {
|
||||
name: "Random Object Placer",
|
||||
shortcut: "R",
|
||||
|
||||
mousePressed: function (button, x, y, modifiers) {
|
||||
if (button !== 1) return;
|
||||
|
||||
var map = tiled.activeAsset;
|
||||
if (!map || !map.isTileMap) return;
|
||||
|
||||
var layer = map.currentLayer;
|
||||
if (!layer || !layer.isObjectLayer) {
|
||||
tiled.warn("Select an object layer first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedTiles = tiled.mapEditor.tilesetsView.selectedTiles;
|
||||
if (!selectedTiles || selectedTiles.length === 0) {
|
||||
tiled.warn("Select some tiles in the Tilesets panel first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tile = selectedTiles[Math.floor(Math.random() * selectedTiles.length)];
|
||||
|
||||
var obj = new MapObject();
|
||||
obj.tile = tile;
|
||||
obj.x = x - tile.width / 2;
|
||||
obj.y = y + tile.height / 2;
|
||||
obj.width = tile.width;
|
||||
obj.height = tile.height;
|
||||
|
||||
// Randomly flip horizontally
|
||||
if (Math.random() < 0.5) {
|
||||
obj.tileFlippedHorizontally = true;
|
||||
}
|
||||
|
||||
layer.addObject(obj);
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue