GKNoiseMap
A sample of procedural noise data from which you can read noise values directly or create noise textures.
Declaration
class GKNoiseMapOverview
Working with procedural noise involves three main steps, one of each of the three major GameplayKit noise classes:
Noise sources (the GKNoiseSource class cluster) represent the core algorithms and parameters for generating noise. You choose a general style of noise by instantiating and configuring one of the concrete GKNoiseSource subclasses.
Noise objects (GKNoise instances) represent the field of noise generated by a noise source. You create a noise object from a noise source, and can then process it or combine it with other noise objects to create more complex noise patterns. Noise objects are lightweight: GameplayKit defers the computation of generating noise and applying noise processing operations until you’re ready to create output.
GKNoiseMap objects are the concrete output of noise generation and processing. Creating a noise map performs the computation described by the GKNoiseSource and GKNoise objects you create it from, filling a 2D grid of a specific size with noise values based on a slice of the noise object’s 3D noise field.
You can apply noise maps in many different ways. Some examples include :
Creating texture images resembling natural phenomena such as clouds, stone surfaces, and wood grain. You can also use noise textures as normal maps to make surfaces appear more natural under lighting. (See the SKTexture init(noiseMap:) method.)
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
SKTileMapclass.)Adding a degree of randomness to otherwise smooth movements. For example, you can make game characters move in a jittery manner, or apply a hand-held motion effect to a game camera.
The content of a noise map is a field of floating-point values that, by default, range from -1.0 to 1.0. You can access these values individually with the value(at:) and interpolatedValue(at:) methods, or create SpriteKit resources from the entire noise map’s values with the methods mentioned above.
A noise map is finite and two-dimensional, but the the noise you sample to create it is three-dimensional and infinite in extent. You can create interesting effects by transforming noise in three dimensions before creating a noise map. For example:
By using a cylindrical noise source and applying the rotate(by:) method, you can sample a slice through the cylinders that creates a wood-grain effect.
By using a Perlin noise source and applying the move(by:) method between multiple samples, you can animate a noise map that simulates the way clouds form, billow, and dissipate over time.
[Image]