因此,我目前正在使用教程制作类似flappybird的游戏,而且我已将所有内容复制到相同的位置,但我的管道只会在选定的位置继续产生并且根本不会水平移动。有想法该怎么解决这个吗?到目前为止,这是我的代码:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if gameStarted == false {
gameStarted = true
Ghost.physicsBody?.affectedByGravity = true
let spawn = SKAction.run { ()in
self.createWalls()
}
let delay = SKAction.wait(forDuration: 2.0)
let spawnDelay = SKAction.sequence([spawn, delay])
let spawnDelayForever = SKAction.repeatForever(spawnDelay)
self.run(spawnDelayForever)
let distance = CGFloat(self.frame.width + wallPair.frame.width)
let movePipes = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * distance))
let removePipes = SKAction.removeFromParent()
moveAndRemove = SKAction.sequence([removePipes, movePipes])
let jumpUpAction = SKAction.moveBy(x: 0, y:180, duration: 0.2)
Ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
Ghost.run(jumpUpAction)
答案 0 :(得分:0)
在您的代码段中,您永远不会调用
self.run(moveAndRemove)
这是执行某个操作所必需的,这可能就是为什么事情只会产生,即用
触发的原因self.run(spawnDelayForever)
你能检查一下情况吗?
答案 1 :(得分:0)
全部修复,我只是移动了块:
let distance = CGFloat(self.frame.width + wallPair.frame.width)
let movePipes = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * distance))
let removePipes = SKAction.removeFromParent()
moveAndRemove = SKAction.sequence([removePipes, movePipes])
并将其移动到第一组括号中。谢谢你的帮助! :)