gpt4 book ai didi

ios - Spritekit touchesEnded 滞后

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:05:56 30 4
gpt4 key购买 nike

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

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

-(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

最佳答案

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

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

关于ios - Spritekit touchesEnded 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22587839/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com