我在场景中有一个物体。当我触摸屏幕时,我希望该物体的y位置变为我的触摸位置的y值。为此,我有以下代码:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
SKNode *player = [self childNodeWithName:@"player"];
UITouch *touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
player.position = CGPointMake(player.position.x, positionInScene.y);
}
这段代码可以实现功能,但是如何让对象以稳定的速度移动到触摸的y位置?不是瞬间跳转到触摸y位置,而是以预定义的速度移动到该位置。