4

Over on the Apple Documents It claimes you can make an infinitely sized SKTileMap

Generating procedural game-world maps resembling natural terrain. You can create game world of infinite size by using procedural noise as its underlying representation, and manage storage and memory efficiently by creating noise maps (and their visual representations) only for the area around a player’s current position. (See the SKTileMap class.)

I can generate realistic terrain with GKNoise like the Apple Documents claim you can.image 1

I cannot, however, make 1 giant infinitely sized SKTileMapNode it would be to intense to run on a device

The Apple Documents say to make an SKTileMapNode only around the players current position (like chunks in minecraft)

how can I achieve this in swift? my RPG needs to be infinitely sized to achieve everything I want to do with this game.

I need the "chunks" to be SKTileMapNodes because I need trees, stone, water, etc. to be added to the map so the player can interact with it.

E. Huckabee
  • 1,788
  • 1
  • 13
  • 29
  • I really should play with tilemaps seems interesting. The idea is you make a map large enough that the player can walk, and also large enough to load the next map area in the background. Since you are doing it via procedural generation, the seed will allow the same type of generation to be created over and over. unfortunately what you are asking for is a lot of work to do, maybe something here can help you https://www.raywenderlich.com/137216/whats-new-spritekit-ios-10-look-tile-maps – Knight0fDragon Nov 08 '17 at 20:38
  • I have been playing around with SKTileMaps as well im actually quite proud of what i achieved with it – E. Huckabee Nov 09 '17 at 09:40

1 Answers1

1

The solution to your problem begins in making the GKNoise tileable. You are probably using GKNoiseMap to generate them. When you use the initializer:

let map = GKNoiseMap(_ noise: GKNoise, size: vector_double2,  
origin: vector_double2, sampleCount: vector_int2, seamless: Bool)

Important: Don't forget to set the "seamless" variable to true.

That way you get a tileable map. It looks better when you make them larger than the screen.

Let's say that a part (tileable) of the map that is your realistic terrain is going to be 2048 by 2048

One map may cover 128x128 tiles, for example. In this case each SKTile would be 16x16 pixels

You make a SKTileMap with 128x128 tiles.

Now the SKTileMap needs a background image, or the tile definitions (in this case, it is the GKNoiseMap, that you generated)

Now you can just use the same GKNoiseMap map, and place next to the first map, in any direction, containing another tile map of 128x128 tiles.

Your map is now 256x128 tiles. When the user scrolls, they can't tell where one image ends and another begins so the whole size of the map can be as large as you want, by repeating the same exercise.

It works well when you generate GKNoiseMap bigger than the screen, when you have to scroll a couple of times before the next GKNoiseMap starts. That way it doesn't get visually repetitive.

The area around "the player's position" can be one map, and then when you scroll, the map can repeat itself, saving you from loading anything else besides the map you already generated. That answers the " and manage storage and memory efficiently by creating noise maps" part of your question.

You should also be careful with Data Storage. If every SKTile needs to store variables different than what the GKNoiseMap will give you, infinite maps can be expensive.

Farini
  • 923
  • 1
  • 18
  • 35