<!--
{
  "documentType" : "article",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/creating-an-edge-loop-around-a-scene",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Creating an Edge Loop Around a Scene"
}
-->

# Creating an Edge Loop Around a Scene

Border your scene with an obstacle that physics bodies cannot penetrate.

## Discussion

When you want to confine your in-app objects to a specific region, use an edge-based physics body to define the area. In an app that models a pool table, for example, the balls are the in-app objects, and the table edges collectively create an *edge loop*. The following code demonstrates creating an edge loop to implement an impenetrable boundary that extends from edge to edge in the scene.

```swift
func createSceneContents() {
    self.backgroundColor = .black
    self.scaleMode = .aspectFit
    self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)