On an iPhone with support for 3D-touch, there is a function in which a long press on the left side of the screen with sufficient force opens it, allowing you to change which application is active. Because of this, when a non-moving touch occurs on the left side of the screen, the touch event is delayed for a second or two until the iPhone verifies that the user is not trying to switch tasks and interacts with the application.
This is a serious problem when developing a game with SpriteKit, as these touches are delayed for a second each time the user presses / holds his finger on the left edge of the screen. I was able to solve this problem by registering the UILongPressGestureRecognizer in the main game scene, disabling TouchesBegan and introducing a custom touch function (used as a gesture recognizer selector):
-(void)handleLongPressGesture:(UITapGestureRecognizer *)gesture { CGPoint location = [gesture locationInView:self.view]; if (gesture.state == UIGestureRecognizerStateBegan) { // } else if (gesture.state == UIGestureRecognizerStateChanged) { // } else if (gesture.state == UIGestureRecognizerStateEnded) { // } else if (gesture.state == UIGestureRecognizerStateCancelled) { // } } -(void)didMoveToView:(SKView *)view { /* Setup your scene here */ UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; longPressGestureRecognizer.delaysTouchesBegan = false; longPressGestureRecognizer.minimumPressDuration = 0; [view addGestureRecognizer:longPressGestureRecognizer]; // continue }
The problem is that I would have to implement a gesture recognizer for each touch (including simultaneous), which, as I expect, the user should enter. This interferes with any TouchesBegan methods as subclasses of SKSpriteNode , SKScene , etc. And kills a lot of functionality.
Is there any way to disable this delay? When registering gestureRecognizer, I was able to set the delaysTouchesBegan property to false. Can I do the same for my SKScene?
To see this problem in action, you can run the default SpriteKit project and click (hold for a second or two) next to the left side of the screen. You will see that there is a delay between touching the screen and displaying SKShapeNodes (as opposed to touching anywhere on the screen).
* Change 1 * For those who are trying to find a way around this for now, you can save the gesture recognizer, but set its cancelsTouchesInView to false. Use the gesture recognizer to do everything you need until TouchesBegan starts ( TouchesBegan will receive the same touch event about a second after recognizing the touch). Once TouchesBegan triggered, you can turn off everything that happens in the gesture recognizer. This seems like a careless fix for me, but it works for now.
Still trying to find a more or less formal solution.
ios objective-c iphone sprite-kit touchesbegan
Andriko13
source share