在touchesBegan中创建Sprite,然后使用UIPanGestureRecognizer移动,但延迟很小

时间:2014-05-14 13:04:07

标签: ios ios7 sprite-kit

我正在使用SpriteKit创建一个应用,在SKSpriteNode中创建一个touchesBegan对象,然后当您在屏幕上平移时,它会随之移动对象。

但是,当我触摸屏幕时,精灵会按预期创建,然后当我移动手指时;精灵保持在同一个地方,小延迟然后移动到我的手指所在的位置。

我的代码如下:

-(void)handlePan: (UIPanGestureRecognizer*) gestureRecognizer{

if (([gestureRecognizer state] == UIGestureRecognizerStateBegan) || ([gestureRecognizer state] == UIGestureRecognizerStateChanged))
{

    CGPoint newLocation = [scene convertPointFromView:[gestureRecognizer locationInView:self.view]];
    scene.finger.position = newLocation;


}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
{
    NSLog(@"Ended");

    [scene.finger removeFromParent];
    scene.finger = nil;
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

for (UITouch *touch in touches) {
    CGPoint location = [self convertPointFromView:[touch locationInView:self.view]];
    [self addFingerSprite:location];
}

}

任何想法,我如何解决这个小延迟问题?

1 个答案:

答案 0 :(得分:1)

延迟是由使用PanGestureRecognizer引起的。在系统识别出锅正在发生之前需要一小段时间。请改用touchesMoved