2016-07-08 11 views
1

私のゲームをスウィフト1から移行していますが、この機能を修正する方法がわかりません。タッチをしていない場合は、ボールを静止したままにしておく必要があります。これは私が持っているコードとエラーを取得し続けるtouchesBeganの無効な再宣言。私はしばらくの間立ち往生していて、触っていないときにボールが動くのを止めることはできません。あなたがボールをユーザが画面から指を切り離したときに停止しなければならない場合には感謝スプライトキットゲームによるオーバーライド機能

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    // do nothing if ad is showing 
    if Ad.share().showing { 
     return 
    } 

    let touch = touches.first! as UITouch 
    let touchedLocation = touch.locationInNode(self) 

    // change the speedXFirst of the ball if it starts 
    if start { 

     // start move 
     let moveRight = touchedLocation.x > CGRectGetMidX(self.frame) 
     let speedX = moveRight ? ballSpeedX : -ballSpeedX 
     ball.speedXFirst = speedX 

    } 

    // start game if it stops 
    else { 
     startGame() 
    } 

} 



    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { //error RIGHT HERE 

    if start { 

     // stop move 
     ball.speedXFirst = 0 
    } 

答えて

1

、助けてください、おそらくあなたはuseしたい:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { 
} 

またはthisをあなたは時にタッチを知る必要がある場合中断されました:

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { 
} 
+1

タッチされた完全な、ありがとうございました –

関連する問題