2015-04-07 30 views
-1

我正在嘗試使用SWIFT雪碧套件聯繫並迅速

一切現在工作得很好,使我的第一場比賽中的精靈套件抱但我可能不知道如何可以處理觸摸並按住屏幕

我是試圖使跳躍功率當玩家按住觸摸,但我不能爲這個

感謝找到事件;)

回答

0

你可以試試這個:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { 
// action when the user touches the screen 
// you can know where did he touch the screen like this 
let touchLocation = touches?.anyObject().locationInView(self/* or your view */) 
} 
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) { 
    // your code here 
} 
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) { 
     // your code here 
} 

這些方法將幫助卡里倒是事件在你的屏幕

+0

謝謝穆罕默德,我知道這種方法,但我怎麼能觸摸並保持! –

+0

我認爲你可以處理touchesHold的這些方法,例如 在你的gameScene中設置一個bool類型的屬性,並在touchesBegan和touchesMoved中將它設置爲true,並在touchesEnded中將它設置爲false,這樣你就可以知道你什麼時候應該做出來那跳躍力量。 我希望它能幫助你。 –

0

據我瞭解,你需要辦理2種情況 1 - 玩家在屏幕上輕擊/節點 - 例如跳躍 2人球員輕擊並保持 - 例如改變跳躍力

我認爲你需要處理「touchesBegan」和「touchesEnded」。 在「touchesBegan」啓動特殊定時器並延遲一段時間後(例如0.5秒)開始播放特殊動畫(顯示當前跳躍力的跳躍電源指示器) on「touchesEnded」 - 停止計時器,停止動畫並計算結果跳躍力基於定時器的值)。

如果您還需要處理跳躍的方向(角度) - 在這種情況下,您還應該處理「touchesMoved」並根據觸摸位置計算當前角度。