Hello Guest

Author Topic: I dynamically create tilemap, but i can't display tile  (Read 8280 times)

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
I dynamically create tilemap, but i can't display tile
« on: September 02, 2014, 04:36:50 am »
hi, i'm sorry, english is not my native language, I try to describe
I really like 2dkit and tilemaps, but i have some trouble
I dynamically create tilemap, but i can't display tile in scene, spriteCollection and tileMapData are used in the demo
Below is my code:


        public tk2dSpriteCollection spriteCollection;
   public tk2dTileMapData tileMapData;

   private tk2dTileMap tileMap;

   void Awake()
   {
      this.tileMap = this.gameObject.AddComponent<tk2dTileMap>();
   }
   
   void Start ()
   {
      this.tileMap.Editor__SpriteCollection = this.spriteCollection.spriteCollection;
      this.tileMap.data = tileMapData;
      this.tileMap.Build ();

      //this.tileMap.SetTile (0, 0, 1, 0);
      //this.tileMap.SpriteCollectionInst.GetSpriteIdByName ("tiles_spritesheet/130");
         }


i have looked at the other code, and i test too, but i have no idea, layer or chunk etc is all empty, no gameObject
thanks for the support. love your product!

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #1 on: September 02, 2014, 04:50:39 am »
I have been thinking about tk2dTileMapEditorData too,  it have paint etc, but i see tilemap , no way i can create and binding
i think if there were any data, i can access to, so that I can dynamically set tile

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #2 on: September 02, 2014, 09:55:07 am »
Do you call build after setting tiles?

This path hasn't really been tested outside the editor, its much easier to have an empty tilemap in the scene, or empty tilemap prefab which you instantiate and you fill the data + Build() after you're done.

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #3 on: September 02, 2014, 10:18:10 am »
Do you call build after setting tiles?

This path hasn't really been tested outside the editor, its much easier to have an empty tilemap in the scene, or empty tilemap prefab which you instantiate and you fill the data + Build() after you're done.


first of all thank you help, i  think a lot of days, finally can take the next step work
i understand what you mean, the empty tilemap which has been created must have tk2dTileMapData and tk2dTileMapEditorData , although they are empty.
but how i fill the tk2dTileMapEditorData, as i only can acess to editorDataGUID

looking forward to your help, thanks




unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #4 on: September 02, 2014, 10:30:10 am »
You don't need to fill editor data for runtime use, it isn't used at runtime.

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #5 on: September 02, 2014, 10:41:28 am »
You don't need to fill editor data for runtime use, it isn't used at runtime.


thanks, this is very helpful to me
but I only can think of is i create two tilemap, one is empty, another is have been generated,
empty tilemap is filled by another
but i think this way is bad, how i better filled empty tilemap
looking forward to your help, thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #6 on: September 02, 2014, 11:03:12 am »
Sorry I dont think I follow - do you want to copy an existing tilemap?

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #7 on: September 02, 2014, 11:10:26 am »
Sorry I dont think I follow - do you want to copy an existing tilemap?
hah, i want to dynamically create tilemap, as my tilemap is infinite, i think i create one tilemap which is more size than one screen,
then i use tk2dTileMapEditorData to constantly fill the tilemap which haved created

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #8 on: September 02, 2014, 11:16:46 am »
You can't use tilemapeditordata at runtime - you should copy the data into your own monobehaviour using an editor script.

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #9 on: September 02, 2014, 11:25:38 am »
You can't use tilemapeditordata at runtime - you should copy the data into your own monobehaviour using an editor script.
Well, thank you very much for the help
i was ready to parsing tilemapeditordata, hah
Thank you again!

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #10 on: September 03, 2014, 05:26:54 pm »
You can't use tilemapeditordata at runtime - you should copy the data into your own monobehaviour using an editor script.
hi,
i go on my game since then day, but sorry I also need your help
i want to ask, where tilemap store data which is used gameobject or sprite or tile in scene
i tested a lot of ways, i think is no. gameobject or sprite or tile only is edited in scene, if i use data which was stored, that will display
i think i now only try to parsing gameobject or sprite or tile only is edited in scene to my data which i created myself
but i still want to listen to your ideas and get your help
this has been bothering me for a long time

thanks very much!!!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #11 on: September 04, 2014, 09:46:14 am »
Sorry I don't follow, can you explain that in a bit more detail? Maybe some pics will help :)

kaishuai007

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #12 on: September 04, 2014, 12:06:32 pm »
Sorry I don't follow, can you explain that in a bit more detail? Maybe some pics will help :)
sorry, i describe the again。
i want to export data which store tile info, such as layer, spriteId, x, y etc. so i test tilemapdata and tilemapeditordata, i found no information I want.
i only found the information associated with the editor, no tile gameobject in scene info
i test again by tilemap, look at code:

if (GUILayout.Button("ExportTileMapEditorData"))
         {
            int iLenLayer = this.tileMap.Layers.Length;
            for(int i = 0; i < iLenLayer; i++)
            {
               tk2dRuntime.TileMap.Layer layer = this.tileMap.Layers;
               int iLenSpriteChunk = layer.spriteChannel.chunks.Length;
               for(int j = 0; j < iLenSpriteChunk; j++)
               {
                  tk2dRuntime.TileMap.SpriteChunk spriteChunk = layer.spriteChannel.chunks[j];
                  int iLenSpriteId = spriteChunk.spriteIds.Length;
                  for(int k = 0; k < iLenSpriteId; k++)
                  {
                     int spriteId = spriteChunk.spriteIds[k];
                     Debug.Log(i + "," + j + "," + k + "," + spriteId);
                  }
               }
            }
         }


i think i export new data by above code, but i need to convert tile position to ensure correct by use GetTileIdAtPosition etc

if you have a better  way, help me, this torture me for a long time, hah

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: I dynamically create tilemap, but i can't display tile
« Reply #13 on: September 05, 2014, 10:03:06 am »
You don't need to know, or care about chunks.

Code: [Select]
for (int i = 0; i < iLenLayer...)
{
 for (int y = 0; y < tilemap.height; ++y)
 {
    for (int x = 0; x < tilemap.width; ++x)
    {
        int spriteId =  tilemap.GetTile(x, y, i);
    }
 }
}

That should be it. If you need more detailed sprite info, you can use tilemap.Layer.GetTile / GetRawTileValue.