0

I have clouds of different sizes ( seen in the picture ) and im trying to give them a physics body automatically. But I just dont get how to do it. I have a player, its just something like a Ball so I could go for bodyWithCircleOfRadius.

I make it variable for every spawned cloud with this code :

SKSpriteNode * cloud = [SKSpriteNode spriteNodeWithImageNamed:@"wolke"];
float sizeScale = [self getRandomNumberBetween:0.2 to:0.5];
cloud.xScale = sizeScale;
cloud.yScale = sizeScale;

enter image description here

Now somehow I have to fit a PhysicsBody to it. Id be happy for any help. (maybe an oval or ellipse, but how to make the path variable to its size?)

Kind Regards

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Alexxxx
  • 59
  • 7

1 Answers1

1

For this i would definitely go with bodyWithCircleOfRadius. The reason is a perfect physics body path around an object would take up too much extra computing power. And should only be used when absolutely necessary. According to apple:

When choosing a shape for your physics body, do not be overly precise. More complex shapes require more work to be properly simulated. For volume-based bodies, use the following guidelines:

A circle is the most efficient shape. A path-based polygon is the least efficient shape, and the computational work scales with the complexity of the polygon.

The Code for a circle would start out like this:

SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"sphere.png"];
sprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];