Swift SKSpriteNode: Detect Tap / DoubleTap / LongPress

旧巷老猫 提交于 2019-12-05 10:05:40
topclaudy

You can simply use touch.tapCount inside touchesBegan:

Totka

I never had to detect a double tap, but if I have I will do it like this:

1 - add a local var named alreadyTouch and set it to false when the class is initialized

2 - inside touchesBegin if alreadyTouch is false set it to true else do what you have to

3 - setup a local Timer of 0.2 seconds and add also this to the if else to detect if the touch is rapid enough or not. so start this timer where you set alreadyTouch = true.

Hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!