【发布时间】:2014-07-02 13:32:53
【问题描述】:
我正在使用SpriteKit 创建一个应用程序,它在touchesBegan 中创建一个SKSpriteNode 对象,然后当您在屏幕上平移时,它会随之移动对象。
但是,当我触摸屏幕时,精灵会按预期创建,然后当我移动手指时;精灵会在原地停留一小段时间,然后移动到我手指所在的位置。
我的代码如下:
-(void)handlePan: (UIPanGestureRecognizer*) gestureRecognizer{
if (([gestureRecognizer state] == UIGestureRecognizerStateBegan) || ([gestureRecognizer state] == UIGestureRecognizerStateChanged))
{
CGPoint newLocation = [scene convertPointFromView:[gestureRecognizer locationInView:self.view]];
scene.finger.position = newLocation;
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
{
NSLog(@"Ended");
[scene.finger removeFromParent];
scene.finger = nil;
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint location = [self convertPointFromView:[touch locationInView:self.view]];
[self addFingerSprite:location];
}
}
任何想法,我该如何解决这个小延迟问题?
【问题讨论】:
-
尝试在平移手势处于开始状态而不是在检测到触摸开始时创建精灵
-
嗨 giorashc,我一开始就是这样,但后来我希望它在您触摸屏幕时出现,然后在您在屏幕上平移时移动。
标签: ios ios7 sprite-kit