ios - 一旦有完整的行,如何删除 SKSpriteNode? (像俄罗斯方 block )

标签 ios swift sprite-kit

我正在开发一款类似于俄罗斯方 block 的游戏,因为有掉落的障碍物落在地上并堆积起来。我试图找出一种方法,一旦它已满,就从底行中删除所有 SKSpriteNodes。本质上,我需要删除低于 Y 值的所有节点,但仅当有 5 个(连续 5 个)低于该 Y 值时。

感谢任何帮助!谢谢!

这是一些代码:

func createWall() {

    let wall = SKSpriteNode()

    let random = (arc4random_uniform(5)+1)

    wall.position = CGPointMake(self.frame.width / 10 * (2*(CGFloat(random))-1), self.frame.height + 100)
    wall.size = wallSize
    wall.color = wallColor

    wall.physicsBody = SKPhysicsBody(rectangleOfSize: wall.size)
    wall.physicsBody?.categoryBitMask = PhysicsCatagory.Wall
    wall.physicsBody?.contactTestBitMask = PhysicsCatagory.Hero | PhysicsCatagory.Ground
    wall.physicsBody?.collisionBitMask = PhysicsCatagory.Hero | PhysicsCatagory.Ground | PhysicsCatagory.Wall
    wall.physicsBody?.affectedByGravity = true
    wall.physicsBody?.dynamic = true

    if random == 1 {
        numberInColumnOne += 1
    } else if random == 2 {
        numberInColumnTwo += 1
    } else if random == 3 {
        numberInColumnThree += 1
    } else if random == 4 {
        numberInColumnFour += 1
    } else if random == 5 {
        numberInColumnFive += 1
    }

    self.addChild(wall)

    print(numberInColumnOne)
    print(numberInColumnTwo)
    print(numberInColumnThree)
    print(numberInColumnFour)
    print(numberInColumnFive)

}


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let spawn = SKAction.runBlock({
        () in

        self.createWall()

    })


    let delay = SKAction.waitForDuration(3)
    let spawnDelay = SKAction.sequence([spawn, delay])
    let spawnDelayForever = SKAction.repeatActionForever(spawnDelay)

    self.runAction(spawnDelayForever)

}

最佳答案

这是一个教程,它贯穿了在 swift 中构建俄罗斯方 block 游戏的完整过程,我认为它使用的是 Swift 1,所以要小心,但它应该包含你需要的信息:

https://www.bloc.io/swiftris-build-your-first-ios-game-with-swift#!/

除了提供该引用之外,其余部分取决于您如何实现 block 和网格系统,如果您可以提供更多信息,我会更新答案。

关于ios - 一旦有完整的行,如何删除 SKSpriteNode? (像俄罗斯方 block ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39381262/

相关文章:

ios - SKSpriteNode 在随机路径上的平滑运动

ios - iOs模拟器不再登录到iCloud

ios - Discard all changes in Xcode source control 实际上做了什么?

ios - 在具有不同像素格式的 Metal 纹理之间复制

ios - iOS CoreBluetooth Per/Centr交叉连接

ios - 删除字符串开头的非字母字符

javascript - iOS 11.4 Safari 不遵守 'touch-action: manipulation'

objective-c - 为什么Swift中的字符串、数组、字典都变成了值类型

sprite-kit - CIFilter GaussianBlur 似乎在 iOS9.x 上被破坏了(与 SKEffectNode 一起使用)

ios - SpriteKit Actions.sks 文件需要预加载?