我正在构建一个类似于俄罗斯方 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)
}
这是一个快速构建俄罗斯方 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/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |