如何将圆圈(通过SKShapeNode的SKAction)与球(SKShapeNode)同步?

时间:2014-06-04 12:42:03

标签: sprite-kit scale skaction skshapenode

我尝试将圈子(通过SKAction创建SKShapeNode)与球同步(由SKShapeNode创建)。 这是这段代码。但它不能很好地运作。 我该怎么办?

-(void)makeContents{

    //make ground
    UIBezierPath *groundPath = [UIBezierPath bezierPath];
    [groundPath moveToPoint:CGPointMake(0,250)];
    [groundPath addLineToPoint:CGPointMake(568,100)];
    SKShapeNode *ground = [[SKShapeNode alloc] init];
    ground.path = groundPath.CGPath;
    [self addChild:ground];

    //make ball
    SKSpriteNode *ball = [SKSpriteNode spriteNodeWithImageNamed:@"ball.jpeg"];
    ball.position = CGPointMake(10, 320);
    ball.size = CGSizeMake(20, 20);
    ball.physicsBody.dynamic = YES;
    ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:3];
    [self addChild:ball];

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    //make circle
    UIBezierPath *circlePath = [UIBezierPath bezierPath];
    [circlePath addArcWithCenter:ball.position radius:10 startAngle:0 endAngle:2*M_PI clockwise:NO];
    circle = [[SKShapeNode alloc] init];
    circle.path = circlePath.CGPath;
    circle.strokeColor = [SKColor blackColor];

    //this line added after first post.
    circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:10 center:ball.postion];


    [self addChild:circle];

    //make action
    SKAction *scale = [SKAction sequence:@[[SKAction scaleBy:0.1 duration:2],
                                           [SKAction scaleBy:0 duration:0.01]]];
    [circle runAction:[SKAction repeatActionForever:scale]];

}

提前感谢您的帮助。

0 个答案:

没有答案