当我触摸屏幕时,鸟儿以正确的角度向上旋转,但一旦触摸结束就停留在那里。
我游戏中的墙壁已停止产卵了!?
这是我的代码,如果有人能看到我做错了什么让我知道: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)
}
}