Hello Guest

Author Topic: Most memory efficient way of setting/getting enum in tilemap?  (Read 4967 times)

kabuto202

  • Newbie
  • *
  • Posts: 6
    • View Profile
Most memory efficient way of setting/getting enum in tilemap?
« on: January 09, 2014, 05:37:32 am »
I need to be able to in the editor (or even programatically) set an enum value to a tile, and then access it at runtime. One solution I see to this problem is replacing the tile with a GameObject, however this is hardly efficient. I'm away from my work machine at the moment so I can't play around with it directly. I was considering using SetTileFlags() in the tk2dTileMap class, but I can't actually find any reference as to what a tk2dTileFlags object is.

On a side-note where can I find more info on the tk2dTileMapData class?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #1 on: January 09, 2014, 11:14:12 am »
TileFlags are used to mark tiles as flipped, rotated, etc. Its defined at the top of tk2dTileMap.cs (looks like its accidentally excluded from the documentation, I'll add it in the next update). This is merged into the tileId, so isn't actually a good idea to add your own stuff into it. The easiest option is to maintain your own (2d, or flattened 1D) array the size of the tile map and then storing whatever flags in there.

kabuto202

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #2 on: January 09, 2014, 08:15:57 pm »
I see, the secondary grid idea seems like a viable solution, but since the flags are going to be static values assigned to each tile, I'd like to automate the assignment process. Is there a way to get the index value of a tile in the tileset, from it's X/Y coordinates on the 2dtk grid?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #3 on: January 09, 2014, 10:06:43 pm »
You can use tile map.GetTile to get a tile at each x and y position in the tk2d grid.

kabuto202

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #4 on: January 10, 2014, 12:39:20 am »
Oh! Then I could use the tk2dTileMap.GetTileInfoForTileId(int tileId) method to retrieve the int/float/string values which I can set in the Data tab of the tilemap editor, correct? It may not be an enum in terms readability, but functionally it works all the same. If so, how does the the TileInfo object look like (I don't believe it's in the scripting reference)? Is it just a container for properties?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #5 on: January 10, 2014, 11:23:17 am »
TileInfo is defined here (tk2dTileMapData.cs):
Code: [Select]
[System.Serializable]
public class TileInfo
{
public string stringVal = "";
public int intVal;
public float floatVal;
public bool enablePrefabOffset;
}

The data is a unique reference per sprite, but not per tile. Not sure if it'll solve your problem but here you go :)

kabuto202

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Most memory efficient way of setting/getting enum in tilemap?
« Reply #6 on: January 11, 2014, 01:58:17 am »
Curses! Oh well, I'm sure I'll figure something out. Thanks for your help!