0
votes

I am using the following code to put a floor in my SpriteKit based game:

var floorNode = SKSpriteNode()
var floorBody = SKPhysicsBody(edgeFromPoint: CGPointMake(self.frame.minX, self.frame.minY), toPoint: CGPointMake(self.frame.maxX, self.frame.minY))
floorNode.physicsBody = floorBody
addChild(floorNode)

This places a floor at the bottom of the screen as expected. However as I add more things to the scene, one end of the floor eventually sinks down and everything in the scene that is resting on it slides off into the abyss.

I am at a complete loss here since Apple's documentation says that "an edge-based body does not have mass or volume, and is unaffected by forces or impulses in the system. Edge-based bodies are used to represent volume-less boundaries or hollow spaces in your physics simulation."

Anyone else seen this kind of behavior?

1
If you add view.showsPhysics = true to your didMoveToView function and raise your floor by 10 points, do you see the floor tilting after adding nodes to your scene?0x141E
I already had showsPhysics enabled, but raising the floor by 10 resulted in one of the walls glitching this time. It raised about halfway up the screen and rotated about 40 degrees. Very strange. I have no idea how a static body can suddenly shift like that.Scooter
Which build version of Xcode are you using?0x141E
xCode 6 Beta 5. I wish I could try it in xCode 5 to see if it works differently there, but I wrote it in Swift.Scooter
This doesn't happen in Xcode 6 beta 6A267n.0x141E

1 Answers

0
votes

The easiest way to define floor for your scene, without adding any nodes to it:

self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];

where self is your SKScene.

If you don't want ceiling on the scene, define physicsBody as this:

[SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x,
                                                   self.frame.origin.y,
                                                   self.frame.size.width,
                                                   self.frame.size.height*5)];