0

I try to synchronize circle (create with SKAction by SKShapeNode) to ball (create by SKShapeNode). Here is this code. But it couldn't work well. What should I do?

-(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]];

}

Thank you in advance for your help.

  • You'd have to recreate the SKPhysicsBody with an appropriately sized circle-radius SKPhysicsBody while the action is running. Even then if you have collisions while scaling the ball the resulting behavior will probably not be what you'd expect. – CodeSmile Jun 04 '14 at 14:23
  • @LearnCocos2D:I modified code. And I tried to run this code but it did not work well. After all How do it go well? – user3686701 Jun 05 '14 at 07:16
  • What do you mean by synchronize circle to the ball? – 0x141E Jul 27 '14 at 06:47

0 Answers0