我測試了一個簡單的場景。SpriteKit的didBeginContact不能被調用
Func didBeginContact
不能被調用。
我嘗試使用collisionBitMask
和s1.physicsBody = SKPhysicsBody(circleOfRadius: 100)
。問題持續存在。
我能做些什麼來解決它?
import SpriteKit
class Test2Scene: SKScene, SKPhysicsContactDelegate {
override func didMoveToView(view: SKView) {
physicsWorld.contactDelegate = self
physicsWorld.speed = 0
let s1 = SKSpriteNode(imageNamed: kImagePlayer)
s1.position = CGPointMake(100, 100)
s1.physicsBody = SKPhysicsBody(rectangleOfSize: s1.size)
s1.physicsBody?.categoryBitMask = 1
s1.physicsBody?.contactTestBitMask = 2
//s1.physicsBody?.collisionBitMask = 2
self.addChild(s1)
let s2 = SKSpriteNode(imageNamed: kImagePlayer)
s2.position = CGPointMake(100, 500);
s2.runAction(SKAction.moveToY(0, duration: 1))
s2.physicsBody = SKPhysicsBody(rectangleOfSize: s2.size)
s2.physicsBody?.categoryBitMask = 2
//s2.physicsBody?.collisionBitMask = 1
self.addChild(s2);
print("view did load")
}
func didBeginContact(contact: SKPhysicsContact) {
print("aaa")
}
func didEndContact(contact: SKPhysicsContact) {
print("bbb")
}
}
還有一些東西有關實施'didBeginContact'方法的內部接觸檢測:http://stackoverflow.com/a/36246855/3402095,http://stackoverflow.com/a/27389834/3402095, http://stackoverflow.com/a/20604762/3402095 – Whirlwind