SKAction scale physicsBody

时间:2013-11-05 00:03:05

标签: objective-c sprite-kit skphysicsbody skaction

我真的不知道从哪里开始。我有一个存储在SKSpriteNodephysicsBody中的圆圈图像,它在创建时会反映出尺寸。

我正在使用SKAction来缩小图像的大小,而physicsBody仍保持相同的大小。我怎样才能缩小physicsBody?

我的代码:

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

1 个答案:

答案 0 :(得分:0)

如果您将物理体的大小设置为圆的大小,您可以实现所寻求的目标。

_circle = [SKSpriteNode spriteNodeWithImageNamed:@"cirlce"];
_circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_circle.size.width/2];