Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Drawing your first sprite


It is time to write some game code – fantastic! Open your GameScene.swift file and find the didMoveToView function. Recall that this function fires every time the game switches to this scene. We will use this function to get familiar with the SKSpriteNode class. You will use SKSpriteNode extensively in your game, whenever you want to add a new 2D graphic entity.

Note

The term sprite refers to a 2D graphic or animation that moves around the screen independently from the background. Over time, the term has developed to refer to any game object on the screen in a 2D game. We will create and draw your first sprite in this chapter: a happy little bee.

Building a SKSpriteNode class

Let's begin by drawing a blue square to 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 with artwork. To draw the blue square, add an instance of SKSpriteNode...