16
Support / How to create and pool layers/chunks for infinite sized map. Layer ctrl?
« on: December 16, 2013, 08:47:03 am »
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.
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.