我正在编写游戏,当用户触摸屏幕的左侧或右侧时,“延续水平”会增加。目前仅在用户第一次触摸屏幕时发生增加(我的代码如下)。我希望只要用户将手指放在屏幕上,就可以应用增加功能。我需要做什么?对持续触摸采取行动,而不是仅在触及时触发:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
if (self.x >= touchPoint.x){
self.sustain += 1;
}else if (self.x <= touchPoint.x){
self.sustain += 1;
}
}