SKAction.moveBy 不工作,我不知道为什么

An SKAction.moveBy is not working and i can't tell why

我一直在学习 Jared Davidson 的教程 How to make Flappy Bird,但我不知道为什么使用 SKAction.moveBy 的函数之一无法正常工作。我认为部分问题在于它可能处于横向模式。用户应该触摸导致幽灵跳跃和障碍物开始移动的屏幕。有人请帮忙。这是我的一个函数的代码:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
    if (gameStarted == false)
    {
        gameStarted = true
        let spawn = SKAction.run(
        {
            () in

            self.createObstacles()
        })

        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 + 20)
        let moveObstacles = SKAction.moveBy(x: distance, y: 0, duration: TimeInterval( 0.01*distance))
        let removeObstacles = SKAction.removeFromParent()
        moveAndRemove = SKAction.sequence([moveObstacles, removeObstacles])

        ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        ghost.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 90))


    }
    else
    {
        ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        ghost.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 90))
    }

}

我最近 运行 遇到了同样的问题,并且能够通过移动

来解决它
    let wallDistance = CGFloat(self.frame.size.width + wallPair.frame.width)
    let moveWall = SKAction.moveBy(x:  -wallDistance, y: 0, duration: 
            TimeInterval(0.008 * wallDistance))
    let removeWall = SKAction.removeFromParent()
    moveAndRemove = SKAction.sequence([moveWall, removeWall]) 

在 createWalls 中创建顶墙和底墙的下方。我把它放在 setScales 下。

然后你添加

    wallPair.run(moveAndRemove)

在您将 topWall 和 bottomWall 添加为子项的位置下。