Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement touch and hold for sprite kit?

I recently started working with sprite-kit. I know touchesBegan works for just one tap but is there something i can use that will recognize a touch being held down?

like image 459
user3299383 Avatar asked Oct 24 '25 14:10

user3299383


1 Answers

If you want to implement something like shooting then you need to start shooting in touchesBegan method and stop shooting in touchesEnded method:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self startShooting];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self stopShooting];
}

For other purposes you can add UILongPressGestureRecognizer to the SKScene

like image 196
Andrey Gordeev Avatar answered Oct 27 '25 04:10

Andrey Gordeev