我正在使用 SpriteKit
创建一个应用程序,它在 touchesBegan
中创建一个 SKSpriteNode
对象,然后当您在屏幕上平移时,它移动对象。
但是,当我触摸屏幕时, Sprite 会按预期创建,然后当我移动手指时; Sprite 在同一个地方停留一小段时间,然后移动到我手指所在的位置。
我的代码如下:
-(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];
}
知道如何解决这个小延迟问题吗?
最佳答案
延迟是由于使用 PanGestureRecognizer
造成的。系统需要一段时间才能识别出正在进行平移。请改用 touchesMoved
。
关于ios - 在 touchesBegan 中创建 Sprite,然后使用 UIPanGestureRecognizer 移动但延迟很小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655601/