【问题标题】:swift 3 - making a flappy bird game, horizontal pipe troubleswift 3 - 制作一个飞扬的小鸟游戏,水平管道麻烦
【发布时间】:2017-01-01 04:01:48
【问题描述】:

因此,我目前正在使用教程制作一个类似 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)

【问题讨论】:

  • 您没有提供足够的信息来回答您的问题:您阅读了哪个教程?你的代码 sn-p 打算做什么?
  • 我在看 Jared Davidson 的一个 flappy bird 教程,这段代码的 sn-p 是为了让管道产生并在幽灵从管道中跳过去时从右到左移动,只会向上移动向下。但是我的管道都在同一个位置产卵,节点并没有用“removeFromParent()”行删除自己。我想要的只是一种快速简便的方法来生成管道并将它们从右到左平稳地移动。谢谢

标签: swift sprite-kit flappy-bird-clone


【解决方案1】:

在你的代码 sn-p 中,你永远不会调用

self.run(moveAndRemove)

这是执行操作所必需的,这可能是事情只产生的原因,即触发

self.run(spawnDelayForever)

你能检查一下是不是这样吗?

【讨论】:

  • 同样的问题。管道在彼此之上产卵并且没有从右到左移动。管道也没有被移除
【解决方案2】:

全部固定,我只是移动了块:

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])

并将其移到第一组括号中。非常感谢您的帮助! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多