缩放 SKNode 不一致 [英] Zooming an SKNode inconsistent
问题描述
我已经创建了自己的解决方案,用于在特定 SKNode 上放大或缩小,而无需缩放整个场景,它似乎主要按照我期望的方式工作,但我希望得到两个值得注意的例外在这里输入.首先是代码(这个控制语句在 touchesMoved 方法中):
I have created my own solution for zooming in or out on a specific SKNode without having the zoom the entire scene, and it seems to work mostly how I would expect it to work, with 2 notable exceptions which I am hoping to get input on here. First the code (this control statement is within the touchesMoved method):
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];
}
}
现在的问题:
有时捏和松开并不总是正确的,当这种情况发生时我无法完全确定,捏会表现为松开,反之亦然.
The pinch and unpinch are not always right sometimes, and I cannot quite put my finger on when this is happening, the pinch will behave as an unpinch and vis a versa.
当捏合和解开正确缩放 SKNode 时,它很少像我想要的那样平滑.我觉得有点烦人.
When the pinching and unpinching is scaling the SKNode correctly, it is rarely as smooth as I would like. There is a bit of jerkiness to it which I find annoying.
任何人都可以建议改进此方法吗?谢谢!
Can anyone suggest improvements to this method? Thanks!
推荐答案
这将解决您的问题,感谢 Steffen 的提示.
This will solve your problem, thanks to Steffen for the hints.
- (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;
}
这篇关于缩放 SKNode 不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!