ViewController中的Sprite粒子系统动画 [英] Sprite Particle System animation in viewController

查看:133
本文介绍了ViewController中的Sprite粒子系统动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个macOS单窗口应用程序,并添加了一个模板为 Stars 的Sprite Particle System文件。并具有如下视觉效果:



我想将其添加到我的viewController中,



所以,我想知道怎么了以及我该怎么办?



这是演示仓库:链接此处



粒子系统本身是Xcode中提供的标准星型 SceneKit粒子系统,没有任何更改。

解决方案

我取得了一些进展。如果我将摄像机旋转180度,则可以看到恒星正在后退,因此我们可以判断粒子系统运行正常。在默认方向上,我所看到的只是闪烁的灯光。因此,我认为粒子的Z位置与相机的位置相同,为0。



如果我将系统的节点移离相机

  particleNode.position = SCNVector3(0,0,-20)

我仍然只看到闪烁的灯光。但是,如果我单击SCNView,动画将正常工作。我看到星星向我冲来。



我不明白为什么我必须单击视图才能使其正常工作。我试过 isPlaying = true ,但这没什么区别。


I create a macOS single window application and add a Sprite Particle System file with template Stars. and the visual effect just like this:

And I want to add it to my viewController, as the guide of this answer, I got the result like this, and it was not which I desired:

    override func viewDidLoad() {
        super.viewDidLoad()

        let scene = SCNScene()
        let particlesNode = SCNNode()
        let particleSystem = SCNParticleSystem(named: "Welcome", inDirectory: "")
        particlesNode.addParticleSystem(particleSystem!)
        scene.rootNode.addChildNode(particlesNode)
        skView.backgroundColor = .black
        skView.scene = scene
    }

So, I'm wondering what's wrong and what should I do?

Here is the demo repo: Link Here

The particle system itself is the standard "star" SceneKit particle system available in Xcode, with no changes.

解决方案

Well I made a little progress. If I swivel the camera around 180 degrees, I can see the stars receding, so we can tell that the particle system is running ok. In the default orientation, though, all I saw was blinking lights. So I think the particles are being generated with a Z position of 0, the same as the camera's.

If I move the system's node away from the camera

    particlesNode.position = SCNVector3(0, 0, -20)

I still just see blinking lights. But if I click on the SCNView, the animation works correctly. I see stars coming at me.

I don't understand why I have to click the view to get it to work right. I tried isPlaying = true but that made no difference.

这篇关于ViewController中的Sprite粒子系统动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆