[英]Xcode, Unable to run the didBegin(_contact SKPysics) function
class GameScene: SKScene {
let player = SKSpriteNode(imageNamed: "spaceship")
struct PhysicsCategories {
static let None: UInt32 = 1
static let Player: UInt32 = 0b1
static let Obsticles: UInt32 = 0b10
static let Diamond: UInt32 = 0b100
}
func didBegin(_ contact: SKPhysicsContact) {
var body1 = SKPhysicsBody()
var body2 = SKPhysicsBody()
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
body1 = contact.bodyA
body2 = contact.bodyB
}
else {
body1 = contact.bodyB
body2 = contact.bodyA
}
if body1.categoryBitMask == PhysicsCategories.Player && body2.categoryBitMask == PhysicsCategories.Obsticles {
body1.node?.removeFromParent()
body2.node?.removeFromParent()
}
}
I want to remove the diamond once it come in contact with the player and also the player when it comes in contact with the obstacle.我想在钻石与玩家接触时以及在与障碍物接触时移除钻石。 Currently im unable to register the contact between any of them Im currently using Xcode version 9.4.1.
目前我无法注册他们任何人之间的联系我目前使用 Xcode 9.4.1 版。 Will the problem stay if I update the app to
如果我将应用程序更新为
You've got a lot of things missing here (unless you've a lot of code you're not showing) :您在这里缺少很多东西(除非您有很多代码没有显示):
I've written more details here : How to Detect collision in Swift, Sprite kit我在这里写了更多细节: 如何在 Swift、Sprite 套件中检测碰撞
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.