SKAction moveTo:持续时间:对触摸的CGPoint值没有正确响应

时间:2015-01-30 07:15:16

标签: ios objective-c sprite-kit skspritenode skaction

我正在使用SpriteKit构建一个游戏,我有一架飞机,我想要触摸它。我们的想法是将飞机重新定位到用户触摸的位置。

UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];

CGPoint moveToLocation = point;

SKAction *planeMove = [SKAction moveTo:moveToLocation duration:0.5];

[_plane runAction:planeMove]; // _plane represents the plane sprite.


NSLog(@"Touch Point: %@ ",NSStringFromCGPoint(point));
NSLog(@"Plane Location: %@", NSStringFromCGPoint(_plane.position));

上述代码为触摸点和平面位置提供了不同的结果。因此,触摸后的平面远离期望的点。 例如,我在NSLog中获得的值:

Touch Point: {391, 743}
Location: {393, 672}

1 个答案:

答案 0 :(得分:1)

将第二行更改为

CGPoint point = [touch locationInNode:self];