2D Toolkit Forum

2D Toolkit => Support => Topic started by: DJVDJV on October 04, 2015, 01:37:44 pm

Title: How to move tk2dTileMap
Post by: DJVDJV on October 04, 2015, 01:37:44 pm
Hellos,

How I can set whole  tk2dTileMap place in world. Like I have 2 different map but I want their coordinate 1,1 be in different place in world.

Y, Heikki
Title: Re: How to move tk2dTileMap
Post by: LaserDinosaur on October 04, 2015, 07:49:07 pm
If you're just trying to shift the entire tilemap, you can highlight "Tilemap" in the hierarchy (moving "Tilemap Render Data" wont do anything, it will reset when you hit play) and then move the entire thing using the editor position handles:

(https://dl.dropboxusercontent.com/u/20830426/movingTilemap.png)
Title: Re: How to move tk2dTileMap
Post by: DJVDJV on October 04, 2015, 09:06:12 pm
How I should do this in code wise?
Title: Re: How to move tk2dTileMap
Post by: LaserDinosaur on October 04, 2015, 10:19:22 pm
I'd suggest looking into some tutorials on the transform.position (http://docs.unity3d.com/ScriptReference/Transform-position.html) property. Once you've set the tilemap to the position you want, you can then call the following to rebuild the tilemap at the new location:

Code: [Select]
GetComponent<tk2dTileMap>().Build();
Title: Re: How to move tk2dTileMap
Post by: unikronsoftware on October 05, 2015, 11:13:13 am
At runtime, you should move both the tilemap and the tilemap render data

Code: [Select]
GetComponent<tk2dTielmap>().transform.position = newPosition;
GetComponent<tk2dTielmap>().renderData.transform.position = newPosition;

No need to call build in this case, the above will be way more efficient.