![](/img/trans.png)
[英]In Swift, how can I check that a user is no longer touching the screen after touchesMoved is triggered?
[英]How to check each frame if player is touching screen?
如何檢查播放器是否每幀都在觸摸屏幕? 我想要的東西類似於您在“幾何破折號”游戲中不斷觸摸屏幕時,如果您觸摸地面,則會不斷跳躍。 我嘗試了這個,但是我沒有工作:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = true
}
與touchDown函數相同:
func touchDown(atPoint pos : CGPoint) {
isTouching = true
}
嘗試以下代碼:
var isTouching = false
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = true
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = false
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = true
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = false
}
然后您可以檢查更新循環
if isTouching == true {
do something
}
else {
do something else
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.