2016-02-05 94 views
0

我正在關注iOS遊戲教程。我無法弄清楚這裏有什麼問題。 錯誤在於這兩行。Swift遊戲錯誤信息

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 
    } 
} 

回答

2

您聲明常數爲let precent但隨後嘗試使用percent。仔細檢查你的拼寫。

+0

太愚蠢了。 ;;;;謝謝 : ) – user5874918