Hello Guest

Author Topic: Tilemap - Change sprite collection  (Read 4003 times)

Arkuni

  • Newbie
  • *
  • Posts: 1
    • View Profile
Tilemap - Change sprite collection
« on: August 21, 2013, 04:58:37 pm »
Hey guys,

Simple question: Is it possible to change a tilemap's sprite collection during runtime with scripting?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap - Change sprite collection
« Reply #1 on: August 21, 2013, 05:00:43 pm »
It probably is possible, but it isn't tested or officially supported at the moment. There are a lot of little things that can break when doing this, and it doesn't handle any of those cases. If you can guarantee the sprite collections are 100% compatible with one another, then you can almost certainly do it.

GarthSmith

  • Newbie
  • *
  • Posts: 6
  • Games. Math. Code.
    • View Profile
    • Garth Smith's Website
Re: Tilemap - Change sprite collection
« Reply #2 on: August 21, 2013, 08:12:42 pm »
Hello!

I'm no 2D Toolkit expert, but I have actually been looking though the TileMap code. One of the things that we may do further along in our project is "reskin" a TileMap.

It looks like each tile in the TileMap data is stored using the SpriteID integer indexes. So if you go through your two SpriteCollections and see that each corresponding sprite share the same integer SpriteID, then you should be good to go. The string "name" of each sprite is not enough.

I have not figured out a clean way to reassign the integer SpriteIDs in a SpriteCollection. It looks like it is determined by the order the sprites are added to the collection.

Please take this with a grain of salt as I haven't gotten far enough to actually test swapping in and out SpriteCollections.

 - Garth

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap - Change sprite collection
« Reply #3 on: August 21, 2013, 08:41:46 pm »
You don't have to reassign ids in the sprite collection - you can instead create a spriteId remap from sprite collection 1 -> 2 using names or other identifiers. After that you simply run through the tilemap and swap the GetTile(x,y) remap and reassign the remapped value using SetTile.

The problem then becomes how you handle differences, eg. missing sprites, different sprite sizes, different anchors and so on.