[英]Why do I keep getting this error when I try to sequence my actions in Swift?
This is the error I get. 这是我得到的错误。 I have a sequence that Im using so I could call the actions in order.
我有一个我正在使用的序列,所以我可以按顺序调用这些动作。 I put the function addGameBall() in a runBlock so I could have that action finish last.
我将功能addGameBall()放在runBlock中,这样我就可以最后完成该操作。 Is that the correct way to do that.
那是这样做的正确方法。 Here is the code I have: What am I doing wrong?
这是我的代码:我在做什么错? Thanks!
谢谢!
Attemped to add a SKNode which already has a parent
尝试添加已经具有父级的SKNode
//RightSide
if firstBody.categoryBitMask == GameBallCategory && fourthBody.categoryBitMask == WallCategpory {
println("GoalRight")
let waitBall = SKAction.waitForDuration(1.0)
let removeFromParent = SKAction.removeFromParent()
let respawnBall = SKAction.runBlock(self.addGameBall)
let sequenceThis = SKAction.sequence([waitBall, removeFromParent, respawnBall])
runAction(sequenceThis)
}
"Attempting to add a sknode which already has a parent" means you're adding a node twice. “尝试添加已经有一个父节点的sknode”意味着您要添加一个节点两次。 I can't see your addGameBall code but i'm pretty confident you have a line in their that says.
我看不到您的addGameBall代码,但我非常有信心您在其中写着一行。
self.addChild(ball)//or whatever your code is called
.Everytime this functions runs, the line is executed so the same reference to the ball node is added multiple times which is why the compiler is complaining. self.addChild(ball)//or whatever your code is called
每次运行此函数时,都会执行该行,因此多次引用相同的ball节点,这就是编译器抱怨的原因。 The problem could be solved by declaring ball as a local variable so that when the function runs, a new reference to the node is being created. 可以通过将ball声明为局部变量来解决该问题,以便在函数运行时,将创建对该节点的新引用。 Happy coding.
快乐的编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.