/ / Swiftゲームエラーメッセージ[クローズ] - swift

スウィフトゲームエラーメッセージ[閉じる] - スウィフト

私はiOSのゲームチュートリアルに従っています。ここで何が悪いのかわかりません。 この2行にエラーがあります。

  let newAngle = percent * 180 - 180
cannon.zRotation = CGFloat(newAngle) * CGFloat(M_PI); 180.0

//error is "use of unresolved identifier "percent""

このチュートリアルでは以下を使用します。

  cannon.zRotation = CGFloat(newAngle) * CGFloat(M_PI)/ 180.0

エラーが示唆したように私はそれを変更しました


import SpriteKit

class GameScene: SKScene {
var cannon: SKSpriteNode!
var touchLocation:CGPoint = CGPointZero


override func didMoveToView(view: SKView) {
/* Setup your scene here */
cannon = self.childNodeWithName("cannon") as! SKSpriteNode

}


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
touchLocation = touches.first!.locationInNode(self)
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
touchLocation = touches.first!.locationInNode(self)

}

override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
let precent = touchLocation.x / size.width
let newAngle = percent * 180 - 180
cannon.zRotation = CGFloat(newAngle) *; CGFloat(M_PI); 180.0
}
}

回答:

回答№1は2

次のように定数を宣言します。 let precent しかしそれから使用しようとする percent。スペルをよく確認してください。