<!--
{
  "documentType" : "article",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/drawing-spritekit-content-in-a-view",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Drawing SpriteKit Content in a View"
}
-->

# Drawing SpriteKit Content in a View

Display visual content using SpriteKit.

## Discussion

Display SpriteKit content on the screen by configuring a SpriteKit renderer, its scene, and the visual objects you lay out on top of the scene. SpriteKit provides objects that are designed specifically for various types of content (see [Nodes for Scene Building](/documentation/SpriteKit/nodes-for-scene-building)), but for simplicity, this article displays an image in a view.

> Note:
> There are other ways to draw SpriteKit content besides using a view. See <doc://com.apple.spritekit/documentation/SpriteKit/choosing-a-spritekit-scene-renderer> for options.

![Screenshot of on the app window displaying an image (a sprite) using SpriteKit.](images/com.apple.spritekit/media-3016873@2x.png)

Because the code in this article sets up a view, you put the lines from each of the following code listings into a view controller’s <doc://com.apple.documentation/documentation/UIKit/UIViewController/viewDidLoad()> function.

### Create the Scene

Everything displayed with SpriteKit is done through a scene object, which is an instance of [`SKScene`](/documentation/SpriteKit/SKScene). Use the following code to set up a basic scene:

```swift
let scene = SKScene(size: skView.bounds.size)

// Set the scene coordinates (0, 0) to the center of the screen.
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
```

When you pass the `size` of the view’s `bounds` to the scene initializer, you size the scene to the view’s size. When you set the scene’s [`anchorPoint`](/documentation/SpriteKit/SKScene/anchorPoint) to `(0.5, 0.5)`, you determine that the coordinates (0, 0) map to the center of the view.

For further discussion about how setting the `anchorPoint` changes an object’s position in the view, see [Using the Anchor Point to Move the Sprite’s Frame](https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html#//apple_ref/doc/uid/TP40013043-CH9-SW36).

### Lay Out Visual Content on Top of the Scene

You use node objects to display graphics in a SpriteKit view. SpriteKit provides different nodes depending on the content (see Nodes that Draw in  [Nodes for Scene Building](/documentation/SpriteKit/nodes-for-scene-building)). In this case, use an [`SKSpriteNode`](/documentation/SpriteKit/SKSpriteNode) to display an image in the view:

```swift
let image = SKSpriteNode(imageNamed: "myImage.png")

// Add the image to the scene.
scene.addChild(image)
```

The functions to lay out content in a scene are covered in more detail in [Accessing and Modifying the Node Tree](/documentation/SpriteKit/accessing-and-modifying-the-node-tree).

### Present the Scene Inside a View

After you set up the scene, you display it in the view by calling [`presentScene(_:)`](/documentation/SpriteKit/SKView/presentScene(_:)):

```swift
if let skView = self.view as? SKView { 
    skView.presentScene(scene)
}
```

Because the code in this article sets up a view, you add it to your view controller’s <doc://com.apple.documentation/documentation/UIKit/UIViewController/viewDidLoad()> function.

---

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)