Adding a spark particle sprite inside a view controller

戏子无情 提交于 2019-12-04 15:32:27

As mentioned by @mnuages, you can use .scnp file instead of .sks, which is a SceneKit Particle System.

So the steps are:

  1. Create a SceneKit Particle System, I called it ConfettiSceneKitParticleSystem.scnp
  2. Then in your art-board, select the view and select the class SCNView for it like in the printscreen of the question
  3. In your UIViewController:

    class SomeVC: UIViewController {

    @IBOutlet weak var particles: SCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        let scene = SCNScene()        
        let particlesNode = SCNNode()
        let particleSystem = SCNParticleSystem(named: "ConfettiSceneKitParticleSystem", inDirectory: "")
        particlesNode.addParticleSystem(particleSystem!)
        scene.rootNode.addChildNode(particlesNode)
        particles.scene = scene
    }
    

    }

Et Voila...you have you animation :)

.sks files are SpriteKit particle systems. You can also create SceneKit particle systems in Xcode, they are .scnp files.

A .scnp file is basically an archived SCNParticleSystem that you can load with NSKeyedUnarchiver and add to your scene using -addParticleSystem:withTransform:.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!