缩放SKNode不一致 [英] Zooming an SKNode inconsistent

查看:109
本文介绍了缩放SKNode不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的放大或缩小特定SKNode的解决方案,而没有缩放整个场景,它似乎主要用于我期望它的工作方式,我希望得到2个明显的例外情况在这里输入。首先是代码(此控制语句在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];
        }
    }

现在出现问题:


  1. 有时候捏合和捏合并不总是正确的,当发生这种情况时我无法完全按下手指,捏合会表现为一种不均匀的反之亦然。

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆