2D Toolkit Forum
2D Toolkit => Support => Topic started by: dividity on September 10, 2015, 06:59:52 pm
-
Hi,
I'm making a game that requires my terrain (tilemap) to be very big, and procedurally generated. The shape of the level I can change by means of SetTile and such, and is working like a charm, but now I want to be able to dynamically add tilemaps to the scene according to the position of the player.
I saw in a post a recommendation to use LoadLevelAdditiveAsync, but with this approach, unless I understood incorrectly, I'd have to have a scene for each tilemap I want to add.
So, what I tried was creating a prefab of the tilemap and instantiating it at runtime, but this has a bizarre behavior (possibly I'm doing something wrong). The newly created tilemap appears on the hierarchy but the Render Data doesn't. I tried Build() and ForceBuild().
I'd really appreciate it if someone could point me in the right direction on how to achieve this.
Or, if someone could point to a solution to building large worlds without me having to write my own tilemap.
Thanks in advance!!!
-
Instantiating tilemaps at runtime should work in the latest version of tk2d, there were issues in older versions... In any case its way way better to do it using additive levels. Even if all you do is write an editor script to automatically create and maintain the scenes for you. It really is so much more efficient, and you need a scene to edit the tilemap anyway, so win-win.
-
Thank you for the reply.
If I understand correctly, with this method I can't generate a, let's say, "infinite tilemap". I'd have to create a certain number of scenes beforehand and then load them additively where I want.
Is this correct or am I missing something?
Thanks again,
-
You can create an infinite tilemap by creating the different scenes, loading them in additively as needed and then move into position... Once something goes "out of view" delete it, or better yet pool it.