Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tileset.loadFromTilemap/TileMap.toImage function for scripts. #3519

Closed
MainMemory opened this issue Nov 7, 2022 · 6 comments
Closed
Labels
documentation Issue related to the Tiled Manual. feature It's a feature, not a bug.

Comments

@MainMemory
Copy link

Currently, Tiled can create "metatilesets" that are based on other tilemaps, but only if you create it as a .tsx file. There is no mechanism for loading a TileMap object directly into a Tileset, nor is there a way to generate an Image from a TileMap, which could be another method of implementing this function. There is also no way to retrieve an Image for a given Tile, so if I wanted to do something like this in scripting, I would have to process the original tileset's image, cut it into tiles and place them in a larger image manually.

@MainMemory MainMemory added the feature It's a feature, not a bug. label Nov 7, 2022
@bjorn
Copy link
Member

bjorn commented Nov 11, 2022

There is no mechanism for loading a TileMap object directly into a Tileset

You mean you don't have your map saved as a file, so that you could do the following?

tileset.image = "mapfile.tmx"

I think for the need to load a map generated in script directly as a tileset, it would indeed be nice to have a TileMap.toImage function. I'm worrying a lot about all the parameters for rendering maps to image, as are available when using "Export as Image" or when using the tmxrasterizer, but probably a simple function without parameters, that behaves exactly as if the map was referenced as the source of a tileset, would be a good addition for now.

There is also no way to retrieve an Image for a given Tile

Hmm, yes there could definitely be added a Tile.image property as well, though I would make it read-only despite having Tile.setImage, since directly changing the image is not something covered by the undo system.

@MainMemory
Copy link
Author

If setting the image property on a Tileset can accept a TileMap file, and it reloads the tileset, then that's all I need, but the documentation doesn't say anything about any side effects from setting the image property. That should probably be made more clear if that's the case.

@bjorn
Copy link
Member

bjorn commented Nov 11, 2022

Changing the Tileset.image property should do pretty much the same thing as changing the image of a tileset in the Properties view. Given the required loading of the image in this case, it indeed makes sense to add a note regarding that.

@bjorn bjorn added the documentation Issue related to the Tiled Manual. label Nov 11, 2022
@MainMemory
Copy link
Author

Yes, it works, however there does not seem to be any way to set a transparent color for a Tileset in script, like you can in a .tsx file.

@bjorn
Copy link
Member

bjorn commented Nov 11, 2022

Yes, it works, however there does not seem to be any way to set a transparent color for a Tileset in script, like you can in a .tsx file.

It appears to have been left undocumented, but there is Tileset.transparentColor, which you can assign to by string like tileset.transparentColor = "#FF00FF" (57fa2d2).

@MainMemory
Copy link
Author

Great, thanks!

bjorn added a commit that referenced this issue Nov 11, 2022
Also fixed the type of ImageLayer.transparentColor and added some notes
to Tileset properties that should ideally be set up before the image is
set.

See issue #3519.
@bjorn bjorn closed this as completed in ce75d9b Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issue related to the Tiled Manual. feature It's a feature, not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants