Initializer

init(_:size:origin:sampleCount:seamless:)

Initializes a noise map by sampling from the specified noise object, with the specified parameters.

Declaration

init(_ noise: GKNoise, size: vector_double2, origin: vector_double2, sampleCount: vector_int2, seamless: Bool)

Parameters

noise

The noise object from which to create a noise map.

size

The size of 2D “slice” to take from the unit coordinate space of the noise object.

If you later generate a texture image from the noise map with the SKTexture class, this size is also the pixel dimensions of the texture to generate.

origin

The position of the 2D “slice” to take from the unit coordinate space of the noise object.

sampleCount

The width and height of integer grid for sampling noise values from the noise object.

seamless

true to adjust samples taken from the noise object so that generated texture images can be tiled without visible seams; false otherwise.

Return Value

A new noise map object.

Discussion

GKNoiseSource and GKNoise objects are lightweight descriptions of noise generation and processing parameters. When you create a noise map from a noise object, GameplayKit performs the computation described by those objects to create a grid of noise sample values. You can then read those values (or interpolated values at non-integral positions on that grid) with the methods listed in Accessing Noise Values, or use the SKTexture or SKTileMap classes to generate texture images or tile maps from the generated noise.

The noise field described by a GKNoise object is inherently three-dimensional and infinite in extent. When you create a noise map from a noise object, GameplayKit samples a “slice” of noise values, whose size and position within the z = 0 plane of the noise field you specify with the size and origin parameters. You can take advantage of these features by using GKNoise methods to rotate, translate, and scale the noise field before creating a noise map:

  • Generate wood-grain textures by creating and distorting GKCylindersNoiseSource output, then rotating it to “slice” diagonally along the cylinders.

  • Use one of the GKCoherentNoiseSource classes as the basis for an infinite procedurally-generated game world by translating the noise field, then generating noise maps for areas of the world near the player. Because coherent noise is deterministic, you can discard noise maps when the player leaves an area, and regenerate them when the player comes back.

See Also

Creating a Noise Map

init(GKNoise)

Initializes a noise map by sampling from the specified noise object.

init()

Initializes a noise map with a constant noise value of zero throughout.