Reputation: 19975
How do I create a border for the screen that will create a border around except for the bottom.
I am trying out bodyWithEdgeLoopFromRect
but it creates a border all around including the bottom. (which is the only part I don't want to be bordered)
SKPhysicsBody *borders = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsBody = borders;
self.physicsBody.friction = 0.f;
I also tried bodyWithEdgeFromPoint: toPoint
but still can't figure it out.
I also tried bodyWithPolygonFromPath
but I didn't go too well. Any suggestions to do this? Other than making 3 nodes that will be placed on each border? top, left, right...
Upvotes: 3
Views: 2435
Reputation: 2425
You can create a seemingly bottomless border edge body by resizing the rectangle you're using for the bodyWithEdgeLoopFromRect
:
float bottomOffset = 400.0;
CGRect newFrame = CGRectMake(0, -bottomOffset, self.frame.size.width, self.frame.size.height+bottomOffset);
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:newFrame];
Now the rectangle's bottom is 400 points below the bottom edge of the screen, so your physics bodies will fall through the floor, if that's what you're after. Adjust as you see fit (e.g. add methods removing the nodes when they are below the bottom edge).
Upvotes: 4