放大SKNode不一致

我已经创build了自己的解决scheme来放大或缩小特定的SKNode,而不需要缩小整个场景,而且似乎主要是如何工作的,其中有2个值得注意的例外,我希望能够在这里得到input。 首先是代码(这个控制语句在touchesMoved方法中):

if (touches.count == 2) { // this means there are two fingers on the screen NSArray *fingers = [touches allObjects]; CGPoint fingOneCurr = [fingers[0] locationInNode:self]; CGPoint fingOnePrev = [fingers[0] previousLocationInNode:self]; CGPoint fingTwoCurr = [fingers[1] locationInNode:self]; CGPoint fingTwoPrev = [fingers[1] previousLocationInNode:self]; BOOL yPinch = fingOneCurr.y > fingOnePrev.y && fingTwoCurr.y < fingTwoPrev.y; BOOL yUnpinch = fingOneCurr.y < fingOnePrev.y && fingTwoCurr.y > fingTwoPrev.y; BOOL xPinch = fingOneCurr.x > fingOnePrev.x && fingTwoCurr.x < fingTwoPrev.x; BOOL xUnpinch = fingOneCurr.x < fingOnePrev.x && fingTwoCurr.x > fingTwoPrev.x; if (xUnpinch | yUnpinch) { if (YES) NSLog(@"This means an unpinch is happening"); mapScale = mapScale +.02; [map setScale:mapScale]; } if (xPinch | yPinch) { if (YES) NSLog(@"This means a pinch is happening"); mapScale = mapScale - .02; [map setScale:mapScale]; } } 

现在的问题是:

  1. 捏和unpinch并不总是正确的,有时我不能把我的手指,这种情况发生时,捏将performance为一个unpinch和反之亦然。

  2. 当捏和解锁正确缩放SKNode,它是很less光滑,我想。 我觉得很烦人。

任何人都可以提出改进这种方法? 谢谢!

这将解决您的问题,感谢Steffen的提示。

 - (void)didMoveToView:(SKView *)view { UIPinchGestureRecognizer *precog = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)]; [self.scene.view addGestureRecognizer:precog]; } - (void)handlePinch:(UIPinchGestureRecognizer *) recognizer { //NSLog(@"Pinch %f", recognizer.scale); //[_bg setScale:recognizer.scale]; [_bg runAction:[SKAction scaleBy:recognizer.scale duration:0]]; recognizer.scale = 1; }