我正在与spritekit游戏,有一个明显的100-200毫秒之间的接触开始和结束之间的滞后。
有什么办法能让我加快速度吗?我需要使用触摸结束(以计算向量射线之间的起点和停止点之间的用户接触。
-(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发布于 2014-03-23 14:31:09
大多数UIGestureRecognizer实例延迟转发触摸事件,直到它们“识别”到它们的手势还没有被识别为止。这将导致toucheBegan和/或touchesEnded消息被延迟。
您可以通过手势识别器实例的delayTouchesBegan和delayTouchesEnded属性更改此行为。
https://stackoverflow.com/questions/22587839
复制相似问题