Hello Guest

Author Topic: How to create and pool layers/chunks for infinite sized map. Layer ctrl?  (Read 6190 times)

Euthyphro

  • Newbie
  • *
  • Posts: 20
    • View Profile
I'm trying to create an infinite map with pooled layers and chunks using tk2d. So far I've been able to implement a few different procedural generation algorithms to generate the tile map, but now I'd like to make the map infinite with the following logic. Just need to know how to use it with tk2d specifically to programatically control the layers.

The best way I see fit to do this is I plan to pool a new layer with 4x4 chunk set and use them as the player approaches the end of the current layer it is on. For example, I have a map with 4 x 4 chunks in each layer. I was thinking of creating another layer and as the player approaches the border of layer 0, then the next layer with chunkset is used from a pool and placed beside the previous. If a player is walking right and nears the border a layer, the next layer is pulled from the pool, rendered with the tiledata generated from my procedural generation algorithm, and placed. The previous layer is then pooled. If the player walks back or approaches the border again, the layer/chunk set is pooled.

I realize this is not the correct use of a layer but it seems like a fairly simple and quick way to approach this.

I figure I'll only need a pool size of 4 layers, each with 4x4sets of chunks. If the player approaches the border of the bottom right, then you would need to account for the right, bottom right, and bottom edges of the chunk as the player could move in any of these directions, in which case you need to be ready to account for this seemlessly.

i.e. each cube below is a layer from 0 to 3. The little "." is a player moving towards the bottom right. As the player approaches the border of layer 0, layer 1,2,3 are pulled from a pool and rendered with tiledata to seamlessly border layer 0.

x--------xx--------x
|   0      ||     1    |
|         . ||           |
x--------xx--------x
|     2    ||    3     |
|           ||           |
x--------xx--------x

If the player is approaching the left, same thing as above just different position.

x--------xx--------x
|   2      ||     1    |
|           ||           |
x--------xx--------x
|     3    || .  0     |
|           ||           |
x--------xx--------x


So my question in all of this is what is the best way to reposition and control layers programatically with tk2d? Specifically which methods? I find the documentation for tk2d somewhat lacking when it comes to the tilemap methods and classes outside of basic tk2d tilemap functions:(.


Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to create and pool layers/chunks for infinite sized map. Layer ctrl?
« Reply #1 on: December 16, 2013, 11:49:39 am »
You're not meant to reposition / move chunks in the tile map editor, which is why this isn't documented. Its impossible to manage and support all the permutations of what people could do with it, and we need to draw a line somewhere to make it maintainable.

If you wanted to do this, the static sprite batcher could work quite well - you'd have to step through and position the tiles yourself, but that should be a constant anyway. You'd just have to create the pooled static sprite batchers yourself, and you can pretty much do what you want with them, pool them and recycle as needed. That will almost certainly be easier to manage than trying to force the tile map system to do something it wasn't designed for.

Euthyphro

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: How to create and pool layers/chunks for infinite sized map. Layer ctrl?
« Reply #2 on: December 16, 2013, 01:01:30 pm »
You're not meant to reposition / move chunks in the tile map editor, which is why this isn't documented. Its impossible to manage and support all the permutations of what people could do with it, and we need to draw a line somewhere to make it maintainable.

If you wanted to do this, the static sprite batcher could work quite well - you'd have to step through and position the tiles yourself, but that should be a constant anyway. You'd just have to create the pooled static sprite batchers yourself, and you can pretty much do what you want with them, pool them and recycle as needed. That will almost certainly be easier to manage than trying to force the tile map system to do something it wasn't designed for.

Thanks. I've actually got it to work this way, despite it being unintended. With some modification, it seems to work quite well. You should consider adding more features about this as more and more game dev's are looking to create procedurally generated large scale maps. With your great product, it would be a strong selling point.

One other question, is there a way to tell which layer of a tilemap was clicked with what you have? If not I'll modify the plugin possibly but I'll also try your sprite batcher suggestion as well. The thing is that you can mine through the tiles, so either using sprite batcher to build or the tilemap to build after each tile is modified can be a problem. I have an idea how to increase speed on this but going for what ever takes less time to modify.



Just wanted to add, even with Unity 2D being released, your product is well worth the $65. Unity 4.3 is great but I find SpriteRenderer can be quite slow compared to meshes. Even just slicing up of sprites on tk2d is much better than 4.3.


« Last Edit: December 16, 2013, 01:49:16 pm by Euthyphro »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to create and pool layers/chunks for infinite sized map. Layer ctrl?
« Reply #3 on: December 17, 2013, 09:52:16 pm »
What do you mean by "What layer you've clicked"? If you assign a unity layer to each layer, then you can very easily just check that.