Building a SKSpriteNode class

Let's begin by drawing a blue square on the screen. The SKSpriteNode class can draw both texture graphics and solid blocks of color. It is often helpful to prototype your new game ideas with blocks of color before you spend time on artwork. To draw the blue square, add an instance of SKSpriteNode to the game:

Override func didMove(to view: SKView) { // Make the scene position from its lower left // corner, regardless of any other settings: self.anchorPoint = .zero // Instantiate a constant, mySprite, instance of SKSpriteNode // The SKSpriteNode constructor can set color and size // Note: UIColor is a UIKit class with built-in colorpresets // Note: CGSize is a type we use to set node sizes let mySprite = SKSpriteNode(color: ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.