A count of started touches is not equal to count of finished touches

后端 未结 5 2092
无人共我
无人共我 2021-02-07 10:10

I have the following code for testing purposes:

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

- (v         


        
5条回答
  •  遇见更好的自我
    2021-02-07 10:23

    It appears this is a bug in SKView's touchesBegan: method. From what I can tell, Apple is using a dictionary to associate each UITouch with the object that the touch methods should be forwarded to. From my testing it appears that if there are multiple touches that begin at the same time, only one of the touches gets added to the dictionary. As a result, your scene won't ever receive the touch-related method calls for the other touches, which is why you are seeing the difference between touchesStarted and touchesFinished.

    If you subclass SKView and override the touchesBegan: method, your scene should get the correct calls.

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        for (UITouch *touch in touches) {
            NSSet *newSet = [NSSet setWithObject:touch];
            [super touchesBegan:newSet withEvent:event];
        }
    }
    

    This fixed the problem for me, but it's possible there might be some side effects from calling the super method multiple times.

提交回复
热议问题