velocityField(with:)
Creates a field node that sets the velocity of physics bodies that enter the node’s area based on the pixel values of a texture.
Declaration
class func velocityField(with velocityTexture: SKTexture) -> SKFieldNodeParameters
- velocityTexture:
A normal texture used to specify the velocities at different points in the field.
Return Value
A new velocity field node.
Discussion
When a physics body is affected, its new velocity in each frame is calculated by performing a texture lookup (treating the value as a normal vector) and then multiplying that vector by the strength of the field. The field has an implicit size (region) equal to the size of the texture; physics bodies outside this area are unaffected by the field node.