tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Scripting: Access to Tile subrectangles

Open eishiya opened this issue 1 year ago • 2 comments

As of 1.9, Image Collection tiles can now use only a subrectangle of their image, defined by x, y, width, height properties. This information is not available to scripting. x and y aren't available at all, and the tile size is available, but is read-only.

It would be nice to be able to read and modify these properties via scripting. For example, if I make a tileset out of all my spritesheets and define each tile to just be the first frame of the idle animation, if I then modify the spritesheet, I may want to use a script to automatically update the subrect to the new location of that frame based on the animation metadata. Or I might want to populate an Image Collection with tiles for every frame in a spritesheet via some metadata and automatically assign animations to them.

For Tiles in a regular ("Based on Tileset Image") tileset, it would be great if these properties were available and contained the calculated position and size of the tile (the size already does this). They of course would not be written out to TSX/TSJ files, but they'd be useful for some scripts. For these tilesets, the properties should be effectively read-only, perhaps assigning to them could throw an error or raise a warning.

And of course, if Tile Atlases are implemented, these same fields would be useful to script for them.

eishiya avatar Aug 06 '22 22:08 eishiya

Did I forget to document something? The sub rectangle of a tile can be assigned to this property:

https://github.com/mapeditor/tiled/blob/8b9672c629294cfa63a61c799ed473077e548010/src/tiled/editabletile.h#L45

bjorn avatar Aug 07 '22 19:08 bjorn

There are no instances of imageRect in the TypeScript file or in the online API docs xP Looks like Tile.imageRect does work though and just isn't documented.

eishiya avatar Aug 07 '22 22:08 eishiya