Import pictures from user's photo gallery and add to SKScene as circular image?

97 views Asked by At

It seems the only way to make circles in a SKScene is to either upload a circular image or use SKShapeNodes.

What if we want to let the user import pictures from their address book or photo gallery and turn those pictures into circles (as opposed to rectangles) to be added to a SKScene.

Is this possible?

1

There are 1 answers

0
hippo_san On

Yes, it's possible. You need to create a mask node, which is just a plain shape picture, it's a blank circle in your case, and add it to a crop node. Please consider the following:

func addPhotoToFrame(photoFrame: SKSpriteNode) {
  let pictureNode = SKSpriteNode(imageNamed: "picture")
  pictureNode.name = "PictureNode"

  let maskNode = SKSpriteNode(imageNamed: "picture-frame-mask")
  maskNode.name = "Mask"

  let cropNode = SKCropNode()
  cropNode.addChild(pictureNode)
  cropNode.maskNode = maskNode
  photoFrame.addChild(cropNode)
}