我已经创建了自己的解决方案,用于在特定 SKNode 上放大或缩小,而无需缩放整个场景,它似乎主要按照我期望的方式工作,有两个值得注意的例外,我希望在这里得到输入. 首先是代码(这个控制语句在 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];
}
}
现在的问题:
捏和松开有时并不总是正确的,当这种情况发生时我不能完全把手指放在上面,捏会表现为松开,反之亦然。
当捏合和松开正确缩放 SKNode 时,它很少像我想要的那样平滑。我觉得有点烦人。
任何人都可以建议改进这种方法吗?谢谢!