Contents

init(texture:size:)

Creates a physics body from the contents of a texture.

Declaration

init(texture: SKTexture, size: CGSize)

Parameters

  • texture:

    The texture to convert into a physics body.

  • size:

    The size of the physics body to return.

Return Value

A new volume-based physics body.

Discussion

Use this method when your sprite has a shape that you want replicated in its physics body. The texture is scaled to the new size and then analyzed. A new physics body is created that includes all of the texels in the texture that have a nonzero alpha value. The shape of this body attempts to strike a good balance between performance and accuracy. For example, fine details may be ignored if keeping them would cause a significant performance penalty.

See Also

Creating a Body from a Texture