我正在編寫遊戲,當用戶觸摸屏幕的左側或右側時,「延續水平」會增加。目前僅在用戶第一次觸摸屏幕時發生增加(我的代碼如下)。我希望只要用戶將手指放在屏幕上,就可以應用增加功能。我需要做什麼?對持續觸摸採取行動,而不是僅在觸及時觸發:
-(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;
}
}