首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spritekit touchesEnded滞后

Spritekit touchesEnded滞后
EN

Stack Overflow用户
提问于 2014-03-23 06:37:53
回答 1查看 708关注 0票数 2

我正在与spritekit游戏,有一个明显的100-200毫秒之间的接触开始和结束之间的滞后。

有什么办法能让我加快速度吗?我需要使用触摸结束(以计算向量射线之间的起点和停止点之间的用户接触。

代码语言:javascript
复制
-(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];
}

日志:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-23 14:31:09

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

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22587839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档