0
我用enumerateChildNodesWithName
命令給我所有的塊物理學的,就像這樣:如何讓一個孩子在使用enumerateChildNodesWithName之後做些什麼?
func findBlock(theName:String){
self.enumerateChildNodesWithName("//*"){
node, stop in
if node.name == theName{
node.physicsBody?.categoryBitMask = physicsCategory.block
node.physicsBody?.collisionBitMask = physicsCategory.laser
node.physicsBody?.contactTestBitMask = physicsCategory.laser
}
}
}
現在我只想要塊之一,當它被用激光打消失。但是,如果沒有讓所有其他街區同時消失,我一直無法做到這一點。
我試圖用這行代碼在didBeginContact
找到哪個塊代表第一主體,將其取下:
if firstBody.categoryBitMask == physicsCategory.block && secondBody.categoryBitMask == physicsCategory.laser{
let block = SKSpriteNode()
block.physicsBody = firstBody
block.alpha = 1
let byeBlock = SKAction.fadeOutWithDuration(0.5)
let gone = SKAction.removeFromParent()
let run = SKAction.sequence([byeBlock, gone])
block.runAction(run)
self.removeChildrenInArray([laser])
}
但也結束了沒有工作。 請幫忙!提前致謝!
當塊受到激光擊中時代碼是什麼?我假設你在'didBeginContact'中處理這個... – Whirlwind
@Whirlwind它在'didBeginContact'中。起初,我嘗試使用相同的'enumerateChildNodesWithName'命令刪除該塊,但很明顯,它刪除了屏幕上的每個塊。最近,我試圖這行代碼: –
如果firstBody.categoryBitMask == physicsCategory.block && secondBody.categoryBitMask == physicsCategory.laser { 設塊= SKSpriteNode() block.physicsBody = firstBody block.alpha = 1 讓byeBlock = SKAction.fadeOutWithDuration(0.5) 設消失= SKAction.removeFromParent() 設運行= SKAction.sequence([byeBlock,消失]) block.runAction(運行) self.removeChildrenInArray([激光]) } –