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

时间:2015-07-21 13:58:13

标签: ios sprite-kit touchesmoved

我创建了一个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];

    }

1 个答案:

答案 0 :(得分:0)

检测到移动事件时,会调用

touchesMoved:withEvent:。您无法依赖此方法调用的次数来检测用户手指的移动方式。

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