【问题标题】:How to check if one sknode touched another如何检查一个 sknode 是否触及另一个
【发布时间】:2018-02-11 07:32:35
【问题描述】:

我正在制作一个游戏,其中一个 SKSpriteNode 需要接触另一个 SKSpriteNode 才能击败对手。

 func intersects(node: SKSpriteNode) -> Bool {
            if ball.intersects(ygB) == true{
                ylicount = ylicount - 1
                yourlivescount.text = "\(ylicount)"
                if ylicount == 0{
                    self.view!.window!.rootViewController!.performSegue(withIdentifier: "GameOverViewController", sender: self)
                }
            }else if ball.intersects(egB) == true{
                   elicount = elicount - 1;

                  enemylivescount.text = "\(elicount)"
                    if elicount == 0{
                        levelcount += 1
                        lccalc += 1
                        ball.physicsBody?.restitution =  (ball.physicsBody?.restitution)! - 0.000065416191
                        ep.run(SKAction.moveTo(x: ball.position.x, duration: 0.5 - (lccalc * 0.00001916151134)))
                        elicount += 3
                        ball.position.x = 0
                        ball.position.y = 0
                    }

}

本质上,有两个目标:yg 和 eg。 ygB 是 yg 周围不可见的 SKNode,egB 与 eg 相同。如果球与 ygB 或 egB 相交,代码应该会采取相应的行动

我做错了什么?

【问题讨论】:

    标签: swift nodes skspritenode intersect


    【解决方案1】:

    给要相互接触的两个节点一个 SKPhyiscs body .dynamic。其次,使用位掩码设置碰撞检测。 https://developer.apple.com/documentation/spritekit/skphysicsbody https://developer.apple.com/documentation/spritekit/skphysicscontactdelegate

    【讨论】:

      猜你喜欢
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2011-06-09
      相关资源
      最近更新 更多