SKAction moveTo:duration:对触摸的 CGPoint 值没有正确响应
SKAction moveTo:duration: does not respond correctly on CGPoint value of the touch
我正在使用 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));
上面的代码使用不同的 Touch Point 和 Plane Location 值给出了不希望的结果。因此,触摸后的平面远离期望的点。
例如,我在 NSLog 中得到的值:
Touch Point: {391, 743}
Location: {393, 672}
将您的第二行更改为
CGPoint point = [touch locationInNode:self];
我正在使用 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));
上面的代码使用不同的 Touch Point 和 Plane Location 值给出了不希望的结果。因此,触摸后的平面远离期望的点。 例如,我在 NSLog 中得到的值:
Touch Point: {391, 743}
Location: {393, 672}
将您的第二行更改为
CGPoint point = [touch locationInNode:self];