Kirill
Kirill

Reputation: 1472

How to set Physics definition programmatically in swift?

I can set physics definition at GameScene.sks file:

GameScene.sks

But how can I change these physics definition parameters (body type, allows rotation, category mask,...) in code programmatically ?

Upvotes: 2

Views: 720

Answers (1)

Knight0fDragon
Knight0fDragon

Reputation: 16827

This is real simple, just create a new instance of SKPhysicsBody with whatever type you want, set the properties the way you want it, and then assign a node.

See https://developer.apple.com/reference/spritekit/skphysicsbody for more details.

let physicsBody = SKPhysicsBody(....type)
physicsBody.(someSetting1)
physicsBody.(someSetting2)
physicsBody.(someSetting3)
node.physicsBody = physicsBody

Upvotes: 4

Related Questions