![](/img/trans.png)
[英]Wait after [SKAction playSoundFileNamed:waitForCompletion:]
[英]SKAction wait interval NOT consistent
我有一个函数创建SpriteNode副本并以指定的间隔沿矩形路径移动每个副本。 我对此间隔有一个问题,即操作以不一致的间隔执行,在操作运行时在精灵节点之间产生奇怪的间隙。
var items = [SKSpriteNode]();
let item = SKSpriteNode(imageNamed: "Spaceship");
func createItem(scene: SKScene) {
let square = UIBezierPath(rect: CGRect(x: -300, y: -150, width: 700, height: 300));
let follow = SKAction.follow(square.cgPath, asOffset: false, orientToPath: false, duration: 5.0);
for i in 0..<6 {
if let itemCopy = item.copy() as? SKSpriteNode {
itemCopy.position = CGPoint(x: -300, y: -150);
items.append(itemCopy);
scene.addChild(itemCopy);
let otherWait = SKAction.wait(forDuration: 1.0, withRange: 2.0);
let otherSequence = SKAction.sequence([otherWait, SKAction.repeatForever(follow)]);
itemCopy.run(otherSequence);
}
}
}
我的理解是我不能依赖for loop
来定时,这个问题可能是由此造成的。 有没有办法通过某种回调函数解决这个问题?
这里的问题与for循环无关,但是来自你正在使用wait(forDuration:withRange:)
事实,这是预期的行为。 文件说明:
创建一个随机时间段空闲的动作。
我想你正在寻找wait(forDuration:)
方法,它会工作得很好:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.