Reputation: 65
I am making a game with sprites falling from the sky, and these sprites have collision testing with the player. But, the physics body around the sprite is showing through all the labels and sprite nodes I add above them. I didn't think physics body's even had a color or anything but for some reason I can see them in my game.
Here is a screenshot of the sprite falling behind the SKLabelNode. I made the label's zPosition = 1 so it is in front of the sprites, but an outline of the physics body shows through: Here is a picture of the label node with a small line that is barely visible but is exactly where I set the sprite's physics body to be
As you can see the sprite disappears behind the label but the physics body doesn't.
Here is another image of the game over screen, which is just a lot of nodes added on the game scene and the game actions paused in the background. As you can see, the outline of the sprites are clearly still visible through everything: Here is the second example
Here is my code for creating the sprite's physics bodys:
obstacle.physicsBody = SKPhysicsBody(rectangleOf: obstacle.size)
obstacle.physicsBody?.isDynamic = true
obstacle.physicsBody?.categoryBitMask = obstacleCategory
obstacle.physicsBody?.contactTestBitMask = playerCategory
obstacle.physicsBody?.collisionBitMask = 0
obstacle.physicsBody?.usesPreciseCollisionDetection = false
So how can I make the sprite’s physics body transparent/invisible? Any help would be appreciated!
Upvotes: 2
Views: 542
Reputation: 610
There is a flag, which when set, allows you to see the physics bodies. This is useful for checking collisions etc. In GameviewController, comment out view.showsPhysics = true. So
//view.showsPhysics = true
Upvotes: 3