gmogames
gmogames

Reputation: 3081

SpriteKit Nodes with Gravity False tilted in place

I'm building a menu Game Scene where I have a Logo and 4 buttons, all of those have a SKPhysicsBody with the rectangle size of the image. All of those I only set:

logo.physicsBody = SKPhysicsBody(rectangleOf: logo.size)
logo.physicsBody?.affectedByGravity = false

Full code of creating the objects (all are the same)

logo = SKSpriteNode(imageNamed: "logo")
logo.anchorPoint = CGPoint.zero
logo.name = "logo"
logo.zPosition = 2
logo.size = CGSize(width: 309, height: 272)
logo.setScale(Generic.utilities.getScale())
self.addChild(logo)
logo.position = CGPoint(x: self.frame.width/2 - logo.size.width/2, y: self.frame.height - logo.size.height - 40)
logo.physicsBody = SKPhysicsBody(rectangleOf: logo.size)
logo.physicsBody?.affectedByGravity = false

and during a button press I change all the nodes affectedByGravity to true so they can fall of the screen and new elements can come in.

The problem I'm having is that when I run the app, the elements are all shifted/tilted on the screen and not in their original position Tilted Nodes

All I wanted is for them to stay in their position until I click one of the buttons and then they can fall off the screen.

Any reason why when I set a physics body and affectedByGravity they all tilt like this?

Upvotes: 2

Views: 154

Answers (1)

gmogames
gmogames

Reputation: 3081

Well, Thanks to @RonMyschuk and @Knight0fDragon I found out (didn't know before) that I could add to my Scene loading the following:

skView.showsPhysics = true

Which add border lines around the physicsBody of your nodes, that way you can see them interacting. And by doing that I saw that the physicsBody of one of my nodes was completely in a different position then it should

Borderline around physicsBody

By taking care of this issue, everything went back to normal

Upvotes: 1

Related Questions