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 support for Tileset Atlas #4166

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

deathbeam
Copy link

@deathbeam deathbeam commented Feb 3, 2025

Useful for y-sorting, multi tile objects, base tile images changing, etc.

  • Add new "atlas" property to tileset that determines if tileset is atlas tileset or not
  • Atlas property is set on tileset creation through type
  • When atlas tileset is loaded, if it doesnt have any image rects image rects for every tile on tileset will be generated
  • Atlas tileset always saves all image rects

For controls, go to rearrange tiles mode:

  • Left click dragging on existing tile starts moving it, releasing saves
  • Left click dragging on existing tile corner starts resizing it, releasing saves
  • Left click dragging on empty space starts selection for creating new tile
  • Right click dragging anywhere starts selection for deleting all tiles overlapping the selection
  • Holding shift before pressing right or left click will disable snapping to grid which allows any sized drawing

image

image

image

Closes #1008

@eishiya
Copy link
Contributor

eishiya commented Feb 3, 2025

This sounds like a partial implementation of the Tile Atlas concept discussed in #2863? Image rects were added as a first step towards this. You may want to see the discussion there about why this should probably be a separate tileset type rather than just extending image rects to "Based on Tileset Image" tilesets.

@deathbeam
Copy link
Author

Looking through it, yea. Even though I think you are overcomplicating it a bit there with the off-grid tiles like the 16x19 example there as that one also fits in 16x32 so the grid display can always just remain in the regular baseline grid set on the tileset, so dont think new view is even needed.

New tileset type, I guess the benefit would be to just inherently save all the image recs instead of saving just the custom ones? which means image recs would be able to also get removed (which would be ideal for merging tiles, which is the feature im trying to replicate here from godot and I think godot mostly works like that anyway, and I think you are also talking about ending on something like that eventually).

@deathbeam
Copy link
Author

Ok got some progress done, I for now added boolean "atlas" on the tileset and adjusted how everything is rendered when set to atlas (grid is no longer used at all and every image rect is drawn directly, and indexAt also uses image rects for resolving tiles they are clicking on). Also added ability to delete tiles, add and merge is something I want to look at next after resolving some rendering quirks this still has

image

@deathbeam deathbeam force-pushed the image-rect-tile branch 4 times, most recently from 0e7a8cd to ccf6221 Compare February 3, 2025 21:36
@deathbeam
Copy link
Author

deathbeam commented Feb 3, 2025

image

image

ok switched back to grid view for simplicity and grid spans, now I can delete tiles without breaking grid and selection also works perfectly. Just need logic for adding the tiles back after they are deleted i guess

Also works with animated tiles out of the box:

image

@deathbeam deathbeam changed the title feat: remove image rect restrictions in tilesets feat: Add support for atlas tilesets Feb 3, 2025
@deathbeam
Copy link
Author

I think as far as functionality goes i think i have most of stuff working properly now

Issues:

  • atm im kinda bastardizing rearrange tiles mode for splitting existing multi tile tiles and readding removed tiles back. I think mode like this is ideal tho, but maybe it should be called differently when in tile atlas mode. And maybe it should remove tiles on right click, add on left click, not sure
  • merge multiple tiles into one is only done manually atm, ideally this would be hold and drag in rearrange tiles mode I think
  • after the above is done I think disabling manual input to the image rect would be best
  • no way to regenerate all the image recs from scratch, currently they are generated when tileset is opened without any image rects (maybe new button, or maybe not even needed)

@deathbeam deathbeam marked this pull request as ready for review February 4, 2025 21:03
@deathbeam
Copy link
Author

Ok got merging and everything else done, for now in Rearrange Tiles mode:

  • Tiles can be merged by holding down left click (this creates multi tile tile)
  • Tiles can be split by right clicking on multi tile edges
  • Tiles can be removed from atlas by right clicking single tiles (so needs to be split first then removed) - current limitation, ideally right click hold would delete multiple, but this is probably not super common use case and the visual seection doesnt work for right click, QT limitation maybe?
  • Tiles can be added back to atlas by left clicking empty tiles

@deathbeam deathbeam changed the title feat: Add support for atlas tilesets Add support for atlas tilesets Feb 4, 2025
@deathbeam deathbeam force-pushed the image-rect-tile branch 7 times, most recently from 9a0e2c7 to 750233b Compare February 5, 2025 20:18
@deathbeam deathbeam changed the title Add support for atlas tilesets Add support for Tileset Grid Atlas Feb 5, 2025
@deathbeam deathbeam force-pushed the image-rect-tile branch 7 times, most recently from f89c64e to 5a8ab44 Compare February 5, 2025 23:39
@deathbeam
Copy link
Author

Ok I think this is now properly ready for review, I was doing some testing since yesterday and I think i fixed everything I found and im happy with the implementation. I did not adjusted documentation or stuff like python bindings etc, I think that can be done as finishing touches after this is reviewed and if the implementation even makes sense (I tried my best but I was not familiar with Tiled codebase at all until I started working on this PR).

@deathbeam deathbeam force-pushed the image-rect-tile branch 10 times, most recently from 51d5023 to eba4409 Compare February 13, 2025 14:05
@deathbeam
Copy link
Author

deathbeam commented Feb 13, 2025

Added support for corner resizing as well, with left click drag on existing tile near corners

EDIT:

Also added support for proper snapping with spacing and margin

@deathbeam deathbeam force-pushed the image-rect-tile branch 3 times, most recently from 77a6852 to be1a23b Compare February 13, 2025 21:16
@deathbeam deathbeam force-pushed the image-rect-tile branch 2 times, most recently from c4f78f5 to c4d00a1 Compare February 14, 2025 15:32
Signed-off-by: Tomas Slusny <[email protected]>
Image collections work in same way so make sure the behaviour is
consistent and functional

Signed-off-by: Tomas Slusny <[email protected]>
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.

Tile sheet with different sized tiles
4 participants