试图在触摸开始时旋转鸟,当触摸结束时旋转(场景)



当我触摸屏幕时,鸟以直角旋转,但是一旦触摸结束,就呆在那里。

我游戏中的墙壁已经停止产卵!?

这是我的代码,如果有人看到我做错了什么,请让我知道:d。将非常感谢。谢谢

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

    if gameStarted == false{
        gameStarted = true
        bird.physicsBody?.affectedByGravity = true

        let spawn = SKAction.run({
            () in
            self.createWalls()
        })
        let delay = SKAction.wait(forDuration: 2.0)
        let spawnDelay = SKAction.sequence([delay, spawn])
        let spawnDelayForever = SKAction.repeatForever(spawnDelay)
        self.run(spawnDelayForever)

        let distance = CGFloat(self.frame.width + wallPair.frame.width)
        let movePipes = SKAction.moveBy(x: -distance - 50, y: 0, duration: TimeInterval( 0.01 * distance))
        let removePipes = SKAction.removeFromParent()
        moveAndRemove = SKAction.sequence([movePipes,removePipes])
        bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        bird.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 35))
        let rotateUp = SKAction.rotate(byAngle: 0.2, duration: 0)
        bird.run(rotateUp)

    }
    else{
        if died == true{
        }
        else{
            bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
            bird.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 35))

        }
    }
    for touch in touches{
        let location = touch.location(in: self)
        if died == true{
            if restartButton.contains(location){
                restartScene()
            }
        }
    }

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

    if gameStarted == false{
        gameStarted = true
        bird.physicsBody?.affectedByGravity = true
        let rotateDown = SKAction.rotate(byAngle: -0.2, duration: 0)
        bird.run(rotateDown)
    }
}

这里没有很多信息,而是我所看到的。当您开始触摸时,您将游戏设置为true。因此,您的if语句结束时不会发射,因为游戏是真的。

最新更新