使用不同手速移动 Touches Moved 时,NSUInteger 增量不一致

NSUInteger increment is not consistent when moving with Touches Moved with different hand speeds

我创建了一个 NSUInteger,它在 Touches Moved 方法中每移动一个像素就递增一次。但是增量不一致。看起来快速移动手指会缓慢增加数字,而缓慢移动手指会快速增加数字。

本质上我是在创建一个墨水瓶效果,这样在屏幕上绘图会随着手指的移动而减少墨水,但是随着绘图速度的不同,这不会总是相同的。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    SKLabelNode *touchedNode = (SKLabelNode *)[self nodeAtPoint:positionInScene];

    pathToDraw = CGPathCreateMutable();
    CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
    lineNode = [[SKShapeNode alloc] init];
    lineNode.path = pathToDraw;
    [_gameNode addChild:lineNode];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    CGPathAddLineToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
    lineNode.path = pathToDraw;
    lineNode.name = lineNodeCategoryName;
    lineNode.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:pathToDraw];
    lineNode.physicsBody.categoryBitMask = lineNodeCategory;
    lineNode.physicsBody.contactTestBitMask = bubble1Category|bubble2Category|bubble3Category|bubble4Category|bubble5Category;
    lineNode.physicsBody.collisionBitMask = ballCategory;
    lineNode.physicsBody.dynamic = YES;
    lineNode.strokeColor = [SKColor blackColor];
    lineNode.glowWidth = 3.0;

    testNumber ++;
    testLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)testNumber];

    }

touchesMoved:withEvent: 在检测到 move 事件时被调用。您将无法依靠调用此方法的次数来检测用户手指移动的

您应该尝试依靠手指在两个事件之间移动的距离来增加您的测试数字。