【问题标题】:Spritekit touchesEnded LagSpritekit touchesEnded Lag
【发布时间】:2014-03-23 22:31:09
【问题描述】:

我正在使用 spritekit 制作游戏,触摸开始和触摸结束之间存在明显的 100-200 毫秒延迟。

有什么办法可以加快速度吗?我需要使用 touchesended(计算用户触摸的起点和终点之间的矢量射线。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        touch_start_pt = location;
    }

    touching = true;
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        double distance = sqrt(pow(location.x - touch_start_pt.x, 2) + pow(location.y - touch_start_pt.y, 2));

        if(distance > 2 && touching && !paused){
            [self impulsePlayer:location];
        }
    }

    touching = false;
}



-(void) impulsePlayer : (CGPoint) location{
    touching = false;

    player.physicsBody.velocity = CGVectorMake(0, 0);

    double dx = location.x - touch_start_pt.x;
    double dy = location.y - touch_start_pt.y;

    CGVector impulse_vector = CGVectorMake(dx*main_impulse_divisor, dy*main_impulse_divisor);

    [player.physicsBody applyImpulse:impulse_vector];
}

日志:

2014-03-23 02:50:26.000 Impakt[2398:60b] began
2014-03-23 02:50:26.532 Impakt[2398:60b] ended
2014-03-23 02:50:29.149 Impakt[2398:60b] began
2014-03-23 02:50:29.648 Impakt[2398:60b] ended
2014-03-23 02:50:34.368 Impakt[2398:60b] began
2014-03-23 02:50:34.815 Impakt[2398:60b] ended

【问题讨论】:

  • 这通常不会发生。请为您的 touchesBegan 和 touchesEnded 方法添加代码
  • 这似乎不会引起问题。您可以在 touchesBegan 和 touchesEnded 方法中使用 NSLog,然后在问题中显示带有时间戳的日志吗?
  • 实际上非常一致 ~550ms
  • 你只是在点击节点?因为,你可能只是“徘徊”:P
  • 当然。真的很郁闷哈哈

标签: ios sprite-kit


【解决方案1】:

大多数 UIGestureRecognizer 实例延迟转发触摸事件,直到它们“识别”出他们的手势还没有被识别。这将导致 toucheBegan 和/或 touchesEnded 消息被延迟。

您可以通过手势识别器实例的delayTouchesBegan and delayTouchesEnded 属性更改此行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多