NSUInteger增量不一致移动时触摸移动不同的手速
问题描述:
我已经创建了一个NSUInteger,移动触摸移动方法每像素增加。但增量并不一致。看起来,快速移动手指会缓慢增加数量,而慢慢移动手指会快速增加数量。NSUInteger增量不一致移动时触摸移动不同的手速
本质上,我创建了一个墨水瓶效果,以便在屏幕上绘图时会减少与手指移动一致的墨水量,但绘制速度不同,这不会总是相同。
- (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:
当检测到移动事件被调用。您将无法依靠调用此方法的次数来检测用户的手指如何移动到远端。
您应该尝试依靠手指在两个事件之间行进的距离来增加测试编号。
你能举个简单的例子说明我该如何做到这一点? – user3482617