【发布时间】:2017-04-23 17:33:10
【问题描述】:
当我触摸屏幕时,小鸟以正确的角度向上旋转,但一旦触摸结束,它就会停留在那里。
我游戏中的墙也停止生成了!?
这是我的代码,如果有人能看到我做错了什么,请告诉我: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)
}
}
【问题讨论】:
标签: ios swift rotation scenekit