I am trying to get a transition effect similar to that in super mario run game by Nintendo in sprite kit
I just want a circle cutout to expand revealing the next scene or just revealing the current scene. This is not available as one of the standard iOS sprite kit transitions.
I have done this with a completely black layer covering the entire scene and using SKCropNode to animate an expanding circle to reveal the scene.
The following is the code which is in didMove(to view: SKView)
let fullScreen = SKSpriteNode(color: .black, size: self.size)
let mask = SKSpriteNode(color: .black, size: self.size)
let circle = SKShapeNode(circleOfRadius: self.size.height / 2)
circle.fillColor = .white
circle.blendMode = .subtract
circle.setScale(0.001)
circle.isHidden = true
circle.name = "circleShape"
mask.addChild(circle)
let crop = SKCropNode()
crop.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2)
crop.maskNode = mask
crop.name = "cropNode"
crop.addChild(fullScreen)
crop.zPosition = 100
self.addChild(crop)
let waitAction = SKAction.wait(forDuration: 2.0)
let callAction = SKAction.run({
let cropNode = self.childNode(withName: "cropNode") as! SKCropNode
let maskNode = cropNode.maskNode as! SKSpriteNode
let circleNode = maskNode.childNode(withName: "circleShape") as! SKShapeNode
circleNode.isHidden = false
let scaleAction = SKAction.scale(to: 2.0, duration: 2.0)
scaleAction.timingFunction = scaleAction.easeInQuartic
circleNode.run(scaleAction, completion: {
cropNode.removeFromParent()
})
})
let seqAction = SKAction.sequence([waitAction,callAction])
self.run(seqAction)
This is working in the simulator but not while running on a device (iPad pro 2016 with the latest iOS 10). On the device, no expanding circle appears and the black overlay layer just disappears after the scale action is finished.
My questions:
1) why isn't this working on the device and only on the simulator?
2) is there a better and more efficient way to achieve this transition in sprite kit?
Thanks in advance.
I ended up using SKSpriteNode with a fragment shader. The following is the code in the main scene:
And the following is the shader code which is in a file called transitionShader.fsh
It seems to work with no issues and does not appear to be expensive on the CPU or the memory.