init(vectorNoiseWithSmoothness:size:)
Creates a new texture whose contents are procedurally generated directional noise data.
Declaration
convenience init(vectorNoiseWithSmoothness smoothness: CGFloat, size: CGSize)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.
Return Value
A new noise texture.
Discussion
The noise texture is tileable with itself. The RGB values stored in the texture can be used as directional (XYZ) data. The alpha values are also randomized and can be used as magnitude data, if desired.
The following Swift code creates three sprite nodes with textures generated by
init(vectorNoiseWithSmoothness:size:)
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 vectorTexture = SKTexture(vectorNoiseWithSmoothness: smoothness,
size: size)
let sprite = SKSpriteNode(texture: vectorTexture, size: size)
sprite.position = CGPoint(x: CGFloat(i) * columWidth + (columWidth / 2),
y:
scene.size.height / 2)
scene.addChild(sprite)
}[Image]