【发布时间】: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