-3
我正在開發一款遊戲,它包含在場景中移動的幾個箭頭。我已經設定了一些碰撞,我需要移除與障礙物相遇的箭頭。我設置的非常簡單而且功能強大,但只有一個箭頭,因爲它是數組的元素[0],顯然如果另一個(不是[0])觸及屏障,它將不會從父級移除。儘管需要爲每個數字手動賦值數組元素,有什麼辦法可以將碰撞委託給所有元素嗎?選擇數組中的任何元素
// 3. react to the contact between the two nodes
if firstBody.categoryBitMask == barrier?.physicsBody?.categoryBitMask &&
secondBody.categoryBitMask == arrows[0].physicsBody?.categoryBitMask {
// Player & barrier
gameOver(false)
} else if firstBody.categoryBitMask == goal?.physicsBody?.categoryBitMask && secondBody.categoryBitMask == arrows[0].physicsBody?.categoryBitMask {
// Player & Goal
arrows[0].removeFromParent()
// gameOver(true)
謝謝!
:)
我所有的初始化'categoryBitMask'。問題是每個箭頭在碰撞時應該消失,但它們位於數組內。我需要一個解決方案,只能刪除聯繫人,而不是全部。 –
@AlessandroNardinelli這個解決方案是刪除你的箭頭與你的goall聯繫。你甚至不需要一個數組。 – Darvydas