【发布时间】:2017-08-21 13:19:06
【问题描述】:
我开始研究 iOS 中的 Sprite Kit 游戏,我想了解如何检测球进入篮筐时是否发生碰撞。
为了让事情更容易理解。在我的篮球架上,我有 2 个角(它们是红色的,很容易看到,它们很突出),它们与它们相连,如果球击中它们,它就会被抛出。
我的问题:我想在球击中任何一个角或球进入篮筐时没有击中任何两个角时引起注意。 (就像一种区分正常投掷和完美投掷的得分方法)
更新:
如何在角落设置标志?你能指出我需要使用的功能吗?
如果球进入篮筐,我有一个节点会通知我,它是篮筐中间的钢筋,当它碰撞时,它会增加我的分数。
func didBegin(_ contact: SKPhysicsContact)
{
// check for the ball contacting the scoreZone (scoreZone is the steel bar)
guard let ballBody = ball.physicsBody, let scoreBody = score_zone.physicsBody else {
return
}
// it doesn't matter who touches who, so just use array "contains" to handle both cases
let bodies = [contact.bodyA, contact.bodyB]
if bodies.contains(ballBody) && bodies.contains(scoreBody) && should_detect_score {
// add score
add_score()
}
}
【问题讨论】:
-
你能发布你当前的碰撞检测代码吗?
标签: ios swift sprite-kit skspritenode