SKPhysicsBody area

Hi,


I'm wondering about the area property of SKPhysicsBody.


        let body = SKPhysicsBody(circleOfRadius: 1.0, center: CGPointZero)
        print("\(body.area)")


This code outputs 0.000139626354211941


I'm confused: shouldn't the result be π = 3.141 ... ? Have I missed something in the documentation? Incorrect area also leads to incorrect mass for a given shape and density.

Accepted Reply

It seems SpriteKit scales 150 px as 1 meter in physics calculations. (I cannot find any Apple's documentation, anyone knows something?)

So, 1.0 px = (1.0/150) meters, thus the area is (1.0/150) * (1.0/150) * π = 0.0001396263...

Replies

It seems SpriteKit scales 150 px as 1 meter in physics calculations. (I cannot find any Apple's documentation, anyone knows something?)

So, 1.0 px = (1.0/150) meters, thus the area is (1.0/150) * (1.0/150) * π = 0.0001396263...

Thanks for the reply.


I cannot but wonder why Apple would make this kind of hardcoded choice for us though ...

This description would have affected the API designs:

Often, proportions are more important than the actual values being used.

(Fudging the Numbers in SpriteKit Programming Guide)


The API designer(s) of SpriteKit physics engine might thought that providing programmable scaling factor would make complicated things more complicated...

But all above are just my guess, and at least, this sort of scaling should be noted in a proper document.