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

Scripting: add displayImage property to Tile to get pre-cropped image #3960

Closed
wants to merge 1 commit into from

Conversation

dogboydog
Copy link
Contributor

@dogboydog dogboydog commented Jun 6, 2024

I saw #3918 is marking these as @since 1.11 , so I did the same here, but I could change it.

The idea here was to provide a pre-cropped image (since Tile.image returns the full image) so that you could display it on a dialog. It came up when I was asking if a new type of widget that lets you select & preview a tile (a TileButton like a color picker button) might be useful.

Let me know what you think

Example script:
https://gist.github.com/dogboydog/363a4fec2e7b1c408e9ecc4b93234bde

Example images
image
image

@bjorn
Copy link
Member

bjorn commented Jun 12, 2024

While this looks like a useful addition, I'm not sure if it really makes sense to add it is almost trivially supported by the existing API as follows:

let rect = tile.imageRect;
let displayImage = tile.image.copy(rect.x, rect.y, rect.width, rect.height);

Though I realize the existing behavior of tile.image isn't very intuitive, and we should probably at least add the above snippet to its documentation.

@dogboydog dogboydog closed this Jun 14, 2024
@dogboydog dogboydog deleted the tile_displayImage branch June 14, 2024 15:06
bjorn added a commit to bjorn/tiled-dev that referenced this pull request Jun 14, 2024
Since Tile.image can refer to a larger image, to get only the part
representing the tile one needs to make a copy.

See mapeditor#3960
bjorn added a commit that referenced this pull request Jun 17, 2024
Also provided a snippet to get a tile's image, since Tile.image can 
refer to a larger image that needs to be cropped using Tile.imageRect.

See #3960
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants