다음 스프라이트 키트 코드에 문제가 있습니다. 비행 공이 선과 충돌 할 때를 감지하려고합니다. 그러나 두 사람이 충돌 할 때 아무 일도 일어나지 않습니다. 볼이 장면의 가장자리 안타 그러나 때, 다음이 출력됩니다 :swift : 스프라이트 키트 충돌 및 비트 마스크가 감지되지 않습니다.
접촉 한 bitmask1 : 4294967295 bitmask2 : 4294967295
문제 1 : 왜 라인과 볼의 충돌이 감지되지 않습니다? 문제점 2 : 가장자리 충돌시 비트 마스크가 모두 같은 이유는 무엇입니까? 나는 어떤 것이 있는지 모른다면 나는 시체와 일할 수 없다. 는 touchesMoved (: NSSet, withEvent 이벤트 : 터치 UIEvent를) FUNC
struct PhysicsCategory {
static let None : UInt32 = 0
static let All : UInt32 = UInt32.max
static let Ball : UInt32 = 0b1 // 1
static let Line : UInt32 = 0b10 // 2
static let Shape : UInt32 = 0b100 // 3 or 4?
}
override func didMoveToView(view: SKView) {
/* Setup your scene here */
physicsWorld.contactDelegate = self
self.physicsBody = SKPhysicsBody(edgeLoopFromRect: view.frame);
self.physicsWorld.gravity = CGVectorMake(0.0, 0.0);
let ball = SKShapeNode(circleOfRadius: 5)
ball.fillColor = UIColor.whiteColor()
ball.strokeColor = UIColor.whiteColor()
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.frame.size.width/2)
ball.physicsBody?.velocity = CGVector(dx: 200.0, dy: 200.0)
ball.position = CGPoint(x: view.bounds.width/2, y:view.bounds.height/2)
ball.physicsBody?.friction = 0.0;
ball.physicsBody?.restitution = 1.0;
ball.physicsBody?.linearDamping = 0.0;
ball.physicsBody?.allowsRotation = false
ball.physicsBody?.applyImpulse(CGVector(dx:CGFloat(100), dy:CGFloat(100)));
ball.physicsBody?.categoryBitMask = PhysicsCategory.Ball
ball.physicsBody?.dynamic = true
ball.physicsBody?.contactTestBitMask = PhysicsCategory.Line
ball.physicsBody?.collisionBitMask = PhysicsCategory.Line
self.addChild(ball)
}
재정의 :
회선 물리학 몸 { 은/* 호출 터치는 1 문제 */
touch = touches.anyObject() as UITouch!
var linePhysicsBody = SKPhysicsBody()
linePhysicsBody.categoryBitMask = PhysicsCategory.Line
linePhysicsBody.contactTestBitMask = PhysicsCategory.Ball
linePhysicsBody.collisionBitMask = PhysicsCategory.Ball
linePhysicsBody.dynamic = false
linePhysicsBody.usesPreciseCollisionDetection = true
lineNode = SKShapeNode()
lineNode.physicsBody = linePhysicsBody
lineNode.name = "drawingLine"
lineNode.path = linePath
lineNode.lineWidth = 5.0
lineNode.strokeColor = UIColor.redColor()
lineNode.glowWidth = 1.0
self.addChild(lineNode)
}
func didBeginContact(contact: SKPhysicsContact) {
println("contact \(++tempCounter)")
println("bitmask1: \(contact.bodyA.categoryBitMask)")
println("bitmask2: \(contact.bodyA.categoryBitMask)")
}
지금은 바보 같아요 ... 고마워요! – user3673836
문제 없습니다. 이것은 모든 개발자에게 발생합니다 ;-) – Stefan