Hello Guest

Author Topic: Setting data to individually placed tiles in TileMap  (Read 7153 times)

TMK

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Dragonhead Games
Setting data to individually placed tiles in TileMap
« on: June 29, 2012, 04:13:52 am »
First I just want to mention that 2D Toolkit and TileMap is great, perfect for my needs! There's one issue that I'm wondering how to work around in the best way.

Let's say I have a tile set to a Prefab, e.g. a treasure chest, and I place 3 of them on a tile map.

I'd like to somehow be able to set the data of the 3 placed objects differently. E.g. chest 1 should contain 150 gold, chest 2 contain 50 gold and chest 3 contain 75 gold.

I know I can set the Data of the individual tiles, but that data will then be used for all placed tiles of that type, so in our case, all chests would always contain e.g. 100 gold. I could have 3 different types of tiles in my SpriteCollection, all looking like chests but have different data (gold amount) on them, but that's not the optimal solution.

When drawing the tiles on the TileMap, perhaps a suggestion would be to somehow set the data for each individually placed tile there. A simple system like "String, Float, Int" would work fine for my usage. So basically when painting the tilemap, next to "Brush, Random, Edged" or something, you could possibly add a "Data" button, and when you tap on a tile it opens a "Enter Data" window, where you can insert a String/Float/Int.

To help see which tiles you have already placed data on, you could show a small icon in the top/left corner of those tiles. I could then make the Prefab lookup which Tile it's placed at, and fetch it's the data, and use that.

I can work around this issue though, but the more I use TileMap, it gets more and more awesome & the more cool stuff I want to use it with that would require something like this :) I'm planning to add teleporters to levels in my current game, and setting their data (e.g. tiles with Teleporters with data "ID01" will teleport from and to each other) would be perfect. It would be great for things like enemies too, I could easily have one tile/prefab for an enemy, and set his data/health to customized values.

Thanks!
« Last Edit: June 29, 2012, 04:16:25 am by TMK »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting data to individually placed tiles in TileMap
« Reply #1 on: June 29, 2012, 09:06:25 pm »
That is a great idea.

There is one downside to doing it the way you suggest - in that each partition in the world would need an array for this data, which could possibly be a bit expensive in terms of memory storage. What about something like this -

You have a data-setup page, where you can create N named-pairs of data, eg.

Name: GoldChest/150 (this will appear in the menu as a folder)
ValueInt: 150
ValueString: ""
ValueObject: ""

And then in "data painting mode", you can tick on a tile, then inspect the values, and select from one of these in the dropdown. It won't let you do explicit data storage per tile (you'll be picking from a fixed number of presets) but there are a few huge advantages here, mainly data storage, but also the fact that you can attach objects directly - so say you wanna spawn a particular monster when you interact with a chest, then you could simply get the object and spawn it.

What do you think?

TMK

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Dragonhead Games
Re: Setting data to individually placed tiles in TileMap
« Reply #2 on: June 30, 2012, 02:35:10 am »
Yep, I was afraid it could be memory expensive. An alternative would be to use a List<TileData> list that only contains references to tiles you've set with data, but that might require you to re-code certain parts instead of utilizing what you already have in place.

Your suggestion sounds very good though and for my use it would work great. It will most likely be a lot easier to implement too than what I suggested as well, so if possible it would be awesome to have that feature!

Thanks :)

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: Setting data to individually placed tiles in TileMap
« Reply #3 on: June 30, 2012, 04:30:18 am »
Why not just set whatever values you want on the prefab directly after you've committed the tilemap?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting data to individually placed tiles in TileMap
« Reply #4 on: June 30, 2012, 10:06:48 am »
That would get overriden when the cell is regenerated for whatever reason, and ultimately there's a plan to add streaming support for REALLY big worlds, and those instances won't even exist at that point...