I have created the SpriteKit Particle Emitter file smoke.sks
.
I want to make this animation run in a
UIView
, however, it has no addChild
method and I still have some errors...
I have tried this solution:
func addSmoke() {
//spark particle effect
let sparkEmmitterPath: String = Bundle.main.path(forResource: "smoke", ofType: "sks")!
let sparkEmmiter = NSKeyedUnarchiver.unarchiveObject(withFile: sparkEmmitterPath as String) as! SKEmitterNode
sparkEmmiter.position = CGPoint(x: self.backgroundMaskView.frame.size.width, y: self.backgroundMaskView.frame.size.height/2)
sparkEmmiter.name = "smoke"
sparkEmmiter.zPosition = 1
sparkEmmiter.targetNode = self
self.view.addChild(sparkEmmiter)
}
2 errors:
sparkEmmiter.targetNode = self
Cannot assign value of type 'ViewController' to type 'SKNode?'
self.addChild(sparkEmmiter)
Cannot convert value of type 'SKEmitterNode' to expected argument type 'UIViewController'
Should I also create SpriteKit View (SKView
)?