5

I don't really know where to start. I have an image of a circle stored in an SKSpriteNode and a physicsBody that mirrors the size when it is created.

I am using an SKAction to scale down the size of the image though, and the physicsBody remains the same size. How can I scale down the physicsBody?

My code:

SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"whiteball"];

    sprite.size = CGSizeMake(20, 20);
    sprite.position = CGPointMake(dx, CGRectGetHeight(self.frame)-dy);
    sprite.name = @"ball";
    sprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];

    [self addChild:sprite];

    SKNode *ballNode = [self childNodeWithName:@"ball"];

    if (ballNode != Nil){
        ballNode.name = nil;

        SKAction *delay = [SKAction waitForDuration:3];
        SKAction *scale = [SKAction scaleTo:0 duration:1]; // I want this to scale the physicsBody as well as the spriteNode...
        SKAction *remove = [SKAction removeFromParent];

        //put actions in sequence
        SKAction *moveSequence = [SKAction sequence:@[delay, scale, remove]];

        //run action from node (child of SKLabelNode)
        [ballNode runAction:moveSequence];
    }
Larme
  • 24,190
  • 6
  • 51
  • 81
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
  • Physics body shapes can not be scaled. There's a host of problems associated with scaling physics shapes. Try search, there have been questions about this before with some workarounds. – CodeSmile Nov 05 '13 at 00:31
  • re above http://stackoverflow.com/questions/19305653/skphysicsbody-and-sknode-setscale/19305700#19305700 – DogCoffee Nov 05 '13 at 02:25
  • @maxud Not sure if this fully applies to your question, but check this out http://stackoverflow.com/a/33572073/3402095. – Whirlwind Nov 06 '15 at 17:15

1 Answers1

0

If you set the size of the physicsbody to the size of the circle, you may achieve what you seek.

_circle = [SKSpriteNode spriteNodeWithImageNamed:@"cirlce"];
_circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_circle.size.width/2];
simonkaspers1
  • 616
  • 4
  • 16