문제

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];
    }
도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top