Swift:在节点之间建立联系后没有执行skaction?

时间:2015-04-25 23:25:57

标签: swift sprite-kit

好吧,我在2个节点之间设置了联系人检测 - saviorchicken1。这是在这里设置的:

//This is within GameScene class
var screenTouches = Bool()

    enum ColliderType:UInt32 {
        case Savior = 1
        case Chicken1 = 2
    }

        savior.physicsBody?.categoryBitMask = ColliderType.Savior.toRaw()
        savior.physicsBody?.contactTestBitMask = ColliderType.Chicken1.toRaw()
        savior.physicsBody?.collisionBitMask = ColliderType.Chicken1.toRaw()

    chicken1.physicsBody?.categoryBitMask = ColliderType.Chicken1.toRaw()
    chicken1.physicsBody?.contactTestBitMask = ColliderType.Savior.toRaw()
    chicken1.physicsBody?.collisionBitMask = ColliderType.Savior.toRaw()

//This is outside of Gamescene class 

 //Collision detection


    func didBeginContact(contact: SKPhysicsContact) {

        if (contact.bodyA.categoryBitMask == ColliderType.Savior.toRaw() && contact.bodyB.categoryBitMask == ColliderType.Chicken1.toRaw() )  {

            chicken1.hidden = true

            let chickenGrabbedLeft = SKAction.moveTo(CGPointMake(self.size.width * 0.1,self.size.height * 1.2), duration:0)
            chicken1.runAction(chickenGrabbedLeft)
            println("contact made")

        } else if (contact.bodyA.categoryBitMask == ColliderType.Chicken1.toRaw() && contact.bodyB.categoryBitMask == ColliderType.Savior.toRaw())  {

            chicken1.hidden = true
            let chickenGrabbedLeft = SKAction.moveTo(CGPointMake(self.size.width * 0.1,self.size.height * 1.2), duration:0)
            chicken1.runAction(chickenGrabbedLeft)
            println("contact made")
        }


    }

saviorchicken1联系时,我需要它看起来chicken1已消失。事实上,我有它,以便chicken1在触及savior时隐藏,但这还不够,因为savior仍然与它发生碰撞,用户可以告诉对象是即使它不可见,它仍然存在。

我不想删除chicken1,因为我仍然需要它出现在游戏中。所以我现在试图让chicken1在触及savior时返回到其起始位置(在屏幕外)。我通过将SKAction放在上面的函数中来做到这一点。

它不起作用。当savior触及chicken1时,chicken1仍会被隐藏。它不动。我该怎么办?

0 个答案:

没有答案