【问题标题】:Creating Sprite in touchesBegan and then moves with UIPanGestureRecognizer but small delay在 touchesBegan 中创建 Sprite,然后使用 UIPanGestureRecognizer 移动,但延迟很小
【发布时间】:2014-07-02 13:32:53
【问题描述】:

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

但是,当我触摸屏幕时,精灵会按预期创建,然后当我移动手指时;精灵会在原地停留一小段时间,然后移动到我手指所在的位置。

我的代码如下:

-(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];
}

}

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

【问题讨论】:

  • 尝试在平移手势处于开始状态而不是在检测到触摸开始时创建精灵
  • 嗨 giorashc,我一开始就是这样,但后来我希望它在您触摸屏幕时出现,然后在您在屏幕上平移时移动。

标签: ios ios7 sprite-kit


【解决方案1】:

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

【讨论】:

  • 感谢您的建议,我会看看这是否也能如我所愿。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-04
  • 2013-05-01
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多