有没有办法链接 SceneKit 动画? [英] Is there a way to chain SceneKit Animations?

查看:53
本文介绍了有没有办法链接 SceneKit 动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种链接 SceneKit 动画的方法.

I’m looking for a way of chaining SceneKit animations.

我要向场景添加 x 个节点,我想添加第一个节点,使其淡入,一旦它可见,我们就转到下一个节点,直到所有节点都可见.所以我需要第一个节点上的动画在我们开始第二个节点之前结束.

I’m adding x number of nodes to a scene, I’d like to add the first node, make it fade in and once it’s visible then we go to the next node until all nodes are visible. So I need the animation on the first node to end before we start on the second.

显然,我尝试了一个带有 SCNActions 的 for 循环,但动画是一起批处理的,因此所有节点同时出现.

Obviously I tried a for loop with SCNActions but the animation is batched together so all nodes appear at the same time.

不知道会增加多少个节点,所以没法做序列.

I don’t know how many nodes will be added, so I can’t make a sequence.

处理这个问题的最佳方法是什么?

What would be the best way to handle this?

好的,我想如果在将序列添加到暂停场景之前向节点添加序列(包括增加的等待间隔)

Okay, I've figured that if I add a sequence to the node before I add it to the paused scene (that includes an incremented wait interval)

let sequence = SCNAction.sequence([.wait(duration: delay), .fadeIn(duration: 0.5)])
node.runAction(sequence)

然后我在添加所有节点后取消暂停场景,它实现了我正在寻找的效果.但它看起来很hacky.

then I un-pause the scene once all the nodes are added it achieves the effect that I'm looking for. But it seems hacky.

有更好的方法吗?

推荐答案

暂停/取消暂停 - 嗯,是的,它有效,但感觉如果你开始做更多事情,这可能会导致问题.

Pause/unpause - hmm, yeah it works, but just feels like that might cause problems down the road if you start doing more things.

我喜欢每个 (James P) 的 completionHandler 路线.您可以使用此方法设置多个(和不同的)动画或动作.比如移动到(5,0,0),旋转,动画,当它到达那里时,再次调用它并移动到(10,0,0)等

I like the completionHandler route per (James P). You could set up multiple (and different) animations or movements with this method. Like move to (5,0,0), rotate, animate, and when it gets there, call it again and move to (10,0,0), etc.

如果它们都以相同的方式工作,那么您可以使用计时器来完成,并且如果这就是您正在寻找的东西,那会给您一些一致性.如果你走这条路,请确保在主线程中放置定时器.

You could do it with a timer if they all work the same way and that would give you some consistency if that's what you are looking for. If you go this route, please ensure to put timers in the main thread.

您还可以根据需要创建一些预定义的序列:

You can also create some pre-defined sequences, depending on your needs:

let heartBeat = SCNAction.sequence([
        SCNAction.move(to: SCNVector3(-0.5,  0.0, 0.80), duration: 0.4),
        SCNAction.unhide(),
        SCNAction.fadeIn(duration: 1.0),
        SCNAction.move(to: SCNVector3(-0.3,  0.0, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3(-0.2,  0.2, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3(-0.1, -0.2, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3( 0.0,  0.0, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3( 0.1,  0.5, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3( 0.3, -0.5, 0.80), duration: 0.4),
        SCNAction.move(to: SCNVector3( 0.5,  0.0, 0.80), duration: 0.4),
        SCNAction.fadeOut(duration: 0.1),
        SCNAction.hide()
        ])

node.runAction(SCNAction.repeatForever(heartBeat))

这篇关于有没有办法链接 SceneKit 动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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