Jungen yan
Jungen yan

Reputation: 222

How to edit the physicsbody of SKNode in SpriteKit Editor of Xcode

I am learning SpriteKit, looking the demo application, adventure, I find the SKNode wall have physicsbody, it seems the physicsbody is setup in the SKS file because I searched all the code and find nothing about wall physicsbody setting. all about the physicsbody of wall in code is here:

wallNode.physicsBody!.dynamic = false
wallNode.physicsBody!.categoryBitMask = ColliderType.Wall.rawValue

So I think the way to setup physicsBody of the SKNode is in the SKS file, but in SpriteKit editor, I can't change anyting about the physics body.

Upvotes: 1

Views: 659

Answers (3)

Petr Lazarev
Petr Lazarev

Reputation: 3182

To change physics properties in the Editor, you need to follow this way:

  1. Select you node
  2. Open the "Utilities" panel (the right panel in Xcode)
  3. Open "Attributes Inspector" in it (3rd option)
  4. Scroll down to "Physics Definition" section
  5. Change necessary property

Screenshot (how to find "Physics Definition" section): Screenshot

Upvotes: 0

AMC08
AMC08

Reputation: 301

Yes it is in the SpriteKit scene editor for the sks file. Select the node and in the SKNode inspector towards the bottom there is a "Physics Definition" drop down. I had a hard time finding it also.

Upvotes: 3

Darvas
Darvas

Reputation: 974

You should look here: https://developer.apple.com/library/mac/documentation/SpriteKit/Reference/SKPhysicsBody_Ref/

To add physics to a node, create and configure an SKPhysicsBody object and then assign it to the physicsBody property of the SKNode object. A physics body must be associated with a node object before you apply forces or impulses to it.

You should modify your wall physicsBody depending on what you want. For example:

// Physics body size

bird.physicsBody = SKPhysicsBody(circleOfRadius: bird.size.height/2)

// Not dynamic

bird.physicsBody.dynamic = false

// Can not rotate

bird.physicsBody.allowsRotation = false

Upvotes: 0

Related Questions