Objective c SKAction scale物理体
我真的不知道从哪里开始。我在Objective c SKAction scale物理体,objective-c,sprite-kit,skphysicsbody,skaction,Objective C,Sprite Kit,Skphysicsbody,Skaction,我真的不知道从哪里开始。我在SKSpriteNode和physicsBody中存储了一个圆的图像,该图像在创建时反映了大小 我正在使用SKAction缩小图像的大小,而physicsBody保持不变。我怎样才能缩小身体的比例 我的代码: SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"whiteball"]; sprite.size = CGSizeMake(20, 20); sprite.posi
SKSpriteNode
和physicsBody
中存储了一个圆的图像,该图像在创建时反映了大小
我正在使用SKAction
缩小图像的大小,而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];
}
如果将physicsbody的大小设置为圆的大小,则可以实现所需的目标
_circle = [SKSpriteNode spriteNodeWithImageNamed:@"cirlce"];
_circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_circle.size.width/2];
物理体形状无法缩放。与缩放物理形状相关的问题很多。尝试搜索,之前有一些关于这个问题的解决方法。re over@maxud不确定这是否完全适用于您的问题,但请检查一下。这个答案是如何被接受的?这正是问题中的代码所做的。