Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale a SKPhysicsBody, how?

I'm reasonably sure I've previously seen code somewhere that scales a SKPhysicsBody, but google and the docs aren't helping, making me more confused than normal.

Is there a way to scale a physic's body in SpriteKit?

The docs, here, don't mention anything about it: https://developer.apple.com/reference/spritekit/skphysicsbody

like image 231
Confused Avatar asked Dec 12 '25 00:12

Confused


2 Answers

If you assign a physics body to a sprite and scale that sprite, the physics body will scale with it.

like image 79
claassenApps Avatar answered Dec 16 '25 23:12

claassenApps


So the answer I think to your question is a solid "no"; at least not in anything I've seen before.

If you care to dabble in a workaround:

  1. Create a new physics body that is larger than what you currently have. Make a method or two to accomplish this.

node.physicsBody = scaledPhysicsBody(bodyToScale: xxxx)

2.

I would just make a blank SKNode and child it to whatever it is that you want to be hit-detectable. Then get rid of the parent's physics body and just use the child's. Now, you can scale the child node (and thus the PB) without affecting the graphics of the main sprite.

like image 20
Fluidity Avatar answered Dec 16 '25 23:12

Fluidity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!