Reader small image

You're reading from  Swift Game Development - Third Edition

Product typeBook
Published inSep 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788471152
Edition3rd Edition
Languages
Right arrow
Authors (2):
Siddharth Shekar
Siddharth Shekar
author image
Siddharth Shekar

Siddharth Shekar is a game developer and teacher with over 6 years' industry experience and 12 years' experience in C++ and other programming languages. He is adept at graphics libraries such as OpenGL and Vulkan, and game engines such as Unity and Unreal. He has published games on the iOS and Android app stores. He has also authored books including Swift Game Development, Mastering Android Game Development with Unity, and Learning iOS 8 Game Development Using Swift, all published by Packt Publishing. He currently lives in Auckland, New Zealand, and is a lecturer in the games department at Media Design School. He teaches advanced computer graphics programming, PlayStation 4 native game development, and mentors final year production students.
Read more about Siddharth Shekar

Stephen Haney
Stephen Haney
author image
Stephen Haney

Stephen Haney has written two books on iOS game development. He began his programming journey at the age of 8 years on a dusty, ancient laptop using BASIC. He has been fascinated with building software and games ever since. Now well versed in multiple languages, he enjoys programming as a creative outlet the most. He believes that indie game development is an art forman amazing combination of visual, auditory, and psychological challengesrewarding to both the player and the creator. He enjoyed writing this book and sincerely hopes that it directly furthers your career or hobby.
Read more about Stephen Haney

View More author details
Right arrow

Exploring the SpriteKit demo


Use the project navigator to open up the file named GameScene.swift. Xcode created GameScene.swift to store the default scene of our new game.

What is a scene? SpriteKit uses the concept of scenes to encapsulate each unique area of a game. Think of the scenes in a movie; we will create a scene for the main menu, a scene for the Game Over screen, a scene for each level in our game, and so on. If you are on the main menu of a game and you tap Play, you move from the menu scene to the Level 1 scene.

SpriteKit prepends its class names with the letters "SK"; consequently, the scene class is SKScene.

You will see that there is already some code in this scene. The SpriteKit project template comes with a very short demo. Let's take a quick look at this demo code and use it to test the iOS simulator.

Please do not be concerned with understanding the demo code at this point. Your focus should be on learning about the development environment.

Look for the run toolbar at the top of the Xcode window. It should look something like the following:

Select the iOS device of your choice to simulate using the dropdown on the far right. Which iOS device should you simulate? You are free to use the device of your choice. I will be using an iPhone X for the screenshots in this book, so choose iPhone X if you want your results to match my images perfectly.

Unfortunately, expect your game to play poorly in the simulator. SpriteKit suffers from poor FPS (Frames Per Second) in the iOS simulator. Once our game becomes relatively complex, we will see our FPS drop, even on high-end computers. The simulator will get you through, but it is best if you can plug in a physical device for testing.

It is time for our first glimpse of SpriteKit in action! Press the gray play arrow on the toolbar (handy keyboard shortcut: command + R). Xcode will build the project and launch the simulator. The simulator starts in a new window, so make sure you bring it to the front. You should see a gray background with white text: Hello, World. Click around on the gray background. You will see colorful, spinning boxes spawning wherever you click:

If you have made it this far, congratulations! You have successfully installed and configured everything you need to make your first Swift game.

Once you have finished playing with the spinning squares, you can close the simulator down and return to Xcode. Note that you can use the keyboard command command + Q to exit the simulator, or press the stop button inside Xcode. If you use the stop button, the simulator will remain open and launch your next build faster.

Previous PageNext Page
You have been reading a chapter from
Swift Game Development - Third Edition
Published in: Sep 2018Publisher: PacktISBN-13: 9781788471152
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Siddharth Shekar

Siddharth Shekar is a game developer and teacher with over 6 years' industry experience and 12 years' experience in C++ and other programming languages. He is adept at graphics libraries such as OpenGL and Vulkan, and game engines such as Unity and Unreal. He has published games on the iOS and Android app stores. He has also authored books including Swift Game Development, Mastering Android Game Development with Unity, and Learning iOS 8 Game Development Using Swift, all published by Packt Publishing. He currently lives in Auckland, New Zealand, and is a lecturer in the games department at Media Design School. He teaches advanced computer graphics programming, PlayStation 4 native game development, and mentors final year production students.
Read more about Siddharth Shekar

author image
Stephen Haney

Stephen Haney has written two books on iOS game development. He began his programming journey at the age of 8 years on a dusty, ancient laptop using BASIC. He has been fascinated with building software and games ever since. Now well versed in multiple languages, he enjoys programming as a creative outlet the most. He believes that indie game development is an art forman amazing combination of visual, auditory, and psychological challengesrewarding to both the player and the creator. He enjoyed writing this book and sincerely hopes that it directly furthers your career or hobby.
Read more about Stephen Haney