Ios 精灵套件-将对象移动到触摸位置

Ios 精灵套件-将对象移动到触摸位置,ios,objective-c,sprite-kit,Ios,Objective C,Sprite Kit,我的场景中有一个对象。当我触摸屏幕时,我希望对象的y位置成为我触摸的y位置。为此,我有以下代码: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { SKNode *player = [self childNodeWithName:@"player"]; UITouch *touch = [touches anyObject]; CGPoint positionInScene = [tou

我的场景中有一个对象。当我触摸屏幕时,我希望对象的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位置,而是以预定义的速度移动到触摸y位置。

对不起,这似乎不起作用。我看不到任何变化。非常感谢!我做了一个很小的改变(见编辑),它的工作。你是最棒的!
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    SKNode *player = [self childNodeWithName:@"player"];

    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

  // Determine speed
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;

// Create the actions
SKAction * actionMove = [SKAction moveTo:CGPointMake(player.position.x, positionInScene.y); duration:actualDuration];
[player runAction:actionMove];

}