Adding a spark particle sprite inside a view contr

2019-04-14 01:23发布

I created an .sks particle emitter based on the spark template. My app is a normal app (not a game). When a user clicks a button, I have a new View controller that shows modally over fullscreen so that I can blur the background.

In this modal, I created a view and gave it a class of SCNView see image below:

enter image description here

How can I load the particle .sks file to do the animation on that viewController on the Particles view?

Update How to load a SceneKit particle systems in view controller?

2条回答
虎瘦雄心在
2楼-- · 2019-04-14 02:05

.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:.

查看更多
Emotional °昔
3楼-- · 2019-04-14 02:19

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 :)

查看更多
登录 后发表回答