我正在制作一款游戏,其中一个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是相同的。如果球与ygB或egB
相交,则应该相应地执行代码我做错了什么?
答案 0 :(得分:0)
给你想要互相接触的两个节点一个SKPhyiscs主体.dynamic。其次,使用位掩码设置冲突检测。 https://developer.apple.com/documentation/spritekit/skphysicsbody https://developer.apple.com/documentation/spritekit/skphysicscontactdelegate