Je suis un tutoriel de jeu iOS. Je ne peux pas comprendre ce qui ne va pas ici. L'erreur est sur ces deux lignes.
let newAngle = percent * 180 - 180
cannon.zRotation = CGFloat(newAngle) * CGFloat(M_PI); 180.0
//error is "use of unresolved identifier "percent""
Le tutoriel utilise:
cannon.zRotation = CGFloat(newAngle) * CGFloat(M_PI)/ 180.0
mais je l'ai changé comme erreur suggérée
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
}
}
Réponses:
2 pour la réponse № 1Vous déclarez une constante comme let precent
mais ensuite essayer d'utiliser percent
. Vérifiez votre orthographe avec soin.