简体   繁体   English

当我尝试在Swift中对动作进行排序时,为什么仍会收到此错误?

[英]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.

相关问题 为什么我在Xcode 7中为我的桥接标题不断出现此错误:桥接标题不存在? - Why do I keep getting this error for my bridging Header in Xcode 7: Bridging Header does not exsist? 我尝试编译我的应用程序时出现错误 - Im getting a error when I try and compile my app 从ViewController到TableViewController时,为什么一直出现此错误? - Why do I keep getting this error when going from ViewController to TableViewController? 为什么我在尝试为我的 UITableView 获取 UILabel 时不断收到“致命错误”? - Why do I keep receiving a “fatal error” when trying to fetch a UILabel for my UITableView? 我进行Pod安装时在QuadratTouch中遇到错误? -迅捷3 - Getting an error in QuadratTouch when I do Pod Install? -Swift 3 当我尝试在手机上运行 Xcode 项目时收到错误消息? - I am getting an error message when I try to run a Xcode project on my phone? 在Swift中以编程方式声明约束时,为什么会出现错误? - Why do I get an error when declaring a constraint programmatically in Swift? 尝试启动前置摄像头时出现错误(Swift) - I get an error when I try to initiate the front camera (Swift) 当我尝试登录或注册我的应用程序时,Swift window 层次结构错误? - Swift window hierarchy error when I try to login or sign up in my app? 为什么在尝试使用自己的CollectionViewCell类时出现此错误? - Why I have this error when I try to use my own CollectionViewCell class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM