init(noiseWithSmoothness:size:grayscale:)
Creates a new texture whose contents are procedurally generated color noise data.
Declaration
convenience init(noiseWithSmoothness smoothness: CGFloat, size: CGSize, grayscale: Bool)Parameters
- smoothness:
A value that indicates how similar neighboring texels will be in the resulting texture. The value should be between
0.0and1.0. A value of1.0generates a smooth surface. - size:
The size of the new texture in points.
- grayscale:
If True, all four components of each texel will have equal values. If False, all four values are completely randomized.
Return Value
A new noise texture.
Discussion
Unlike other textures produced by SpriteKit, the texels are not premultiplied by the alpha value. Your custom shaders should compensate for this as necessary.
The following Swift code creates three sprite nodes with textures generated by
init(noiseWithSmoothness:size:grayscale:)
with smoothness values of 0.0, 0.5 and 1.0.
let columWidth = scene.size.width / 3
for i in 0...2 {
let size = CGSize(width: ceil(columWidth),
height: 0.5 * scene.size.height)
let smoothness = CGFloat(i) / 2
let noiseTexture = SKTexture(noiseWithSmoothness: smoothness,
size: size,
grayscale: false)
let sprite = SKSpriteNode(texture: noiseTexture, size: size)
sprite.position = CGPoint(x: CGFloat(i) * columWidth + (columWidth / 2),
y: scene.size.height / 2)
scene.addChild(sprite)
}[Image]