【问题标题】:move Sprite with action用动作移动 Sprite
【发布时间】:2014-06-10 06:05:46
【问题描述】:

如何将精灵拖到屏幕上的某个位置后自动向后移动?

我试过了:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        CGPoint newPosition = CGPointMake(location.x, self.size.height/2);
        self.start.position = newPosition;
        }
    SKAction *moveTo = [SKAction moveToX:self.frame.size.width/2 duration:0.5];
    [self.start runAction:moveTo];
}

【问题讨论】:

  • 什么是self.start.position?

标签: objective-c xcode5 sprite-kit skaction


【解决方案1】:

如果您最初使用moveByX:y:duration: 移动您的精灵,那么您可以使用[yourActionName reversedAction]; 将其移回touchesEnded: 时的初始起点。

【讨论】:

    【解决方案2】:

    您可以使用 -(void)touchesMoved: 来放置精灵。然后使用 -(void)touchesEnded: 方法将其移回原点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多