0
例碰撞(在屏幕上的紅色塊),預先設定的節點不與用戶觸摸的創建的節點
var img = "BlockRed.png"
let sand = SKSpriteNode (imageNamed: img)
var randLoc = arc4random_uniform(26)
sand.position = CGPointMake(location.x - CGFloat(10) + CGFloat(randLoc), location.y)
sand.name = "redSand"
sand.zPosition = 0
self.addChild(sand)
//gravity
sand.physicsBody?.affectedByGravity = true
//contact
sand.physicsBody!.categoryBitMask = PARTICLE
sand.physicsBody?.collisionBitMask = BLOCK | PARTICLE
sand.physicsBody?.contactTestBitMask = BLOCK | PARTICLE
sand.physicsBody = SKPhysicsBody(circleOfRadius: sand.frame.width - 3)
但是,當它們接觸時,顆粒剛好落在壁上。爲什麼會發生這種情況,我該如何解決?
注:
// Constants
let NOTHING: UInt32 = 0x1 << 0
let PARTICLE: UInt32 = 0x1 << 1
let BLOCK: UInt32 = 0x1 << 2
這沒有奏效。還有其他建議嗎? –
你能告訴我你當前的代碼嗎? – rakeshbs
我想通了,我發佈了一個答案。謝謝你的幫助! –