如何检查播放器是否每帧都在触摸屏幕?我想要一些类似的东西,当你在游戏中触摸屏幕几何短跑,如果你触地,你继续跳跃。我尝试了这个,但我没有工作:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isTouching = true
}
与touchDown函数相同:
func touchDown(atPoint pos : CGPoint) {
isTouching = true
}
答案 0 :(得分:2)
请尝试以下代码:
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
}
答案 1 :(得分:1)
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
}