Game Development with Swift
上QQ阅读APP看书,第一时间看更新

Preface

There has never been a better time to be a game developer. The App Store provides a unique opportunity to distribute your ideas to a massive audience. Now, Swift has arrived to bolster our toolkit and provide a smoother development experience. Swift is new, but is already hailed as an excellent, well-designed language. Whether you are new to game development or looking to add to your expertise, I think you will enjoy making games with Swift.

My goal in writing this book is to share a fundamental knowledge of Swift and SpriteKit. We will work through a complete example game so that you learn every step of the Swift development process. Once you finish this text, you will be comfortable designing and publishing your own game ideas to the App Store, from start to finish.

Please reach out with any questions and share your game creations:

E-mail:

Twitter: @sdothaney

The first chapter explores some of Swift's best features. Let's get started!

What this book covers

Chapter 1, Designing Games with Swift, introduces you to best features on Swift, helps you set up your development environment, and launches your first SpriteKit project.

Chapter 2, Sprites, Camera, Actions!, teaches you the basics of drawing and animating with Swift. You will draw sprites, import textures into your project, and center the camera on the main character.

Chapter 3, Mix in the Physics, covers the physics simulation fundamentals: physics bodies, impulses, forces, gravity, collisions, and more.

Chapter 4, Adding Controls, explores various methods of mobile game controls: device tilt and touch input. We will also improve the camera and core gameplay of our example game.

Chapter 5, Spawning Enemies, Coins, and Power-ups, introduces the cast of characters we will use in our example game and shows you how to create custom classes for each NPC type.

Chapter 6, Generating a Never-Ending World, explores the SpriteKit scene editor, builds encounters for the example game, and creates a system to loop encounters endlessly.

Chapter 7, Implementing Collision Events, delves into advanced physics simulation topics and adds custom events when sprites collide.

Chapter 8, Polishing to a Shine – HUD, Parallax Backgrounds, Particles, and More, adds the extra features that make every great game shine. Create parallax backgrounds, learn about SpriteKit's particle emitters, and add a heads-up display overlay to your games.

Chapter 9, Adding Menus and Sounds, builds a basic menu system and illustrates two methods of playing sounds in your games.

Chapter 10, Integrating with Game Center, links our example game to the Apple Game Center for leaderboards, achievements, and friendly challenges.

Chapter 11, Ship It! Preparing for the App Store and Publication, covers the essentials of packaging your game and submitting it to the App Store.

What you need for this book

This book uses the Xcode IDE Version 6.3.2 (Swift 1.2). If you use a different version of Xcode, you will likely encounter syntax differences; Apple is constantly upgrading Swift's syntax.

Visit https://developer.apple.com/xcode/ to download Xcode.

You will need an Apple developer account to integrate your apps with the Game Center and to submit your games to the App Store.

Who this book is for

If you wish to create and publish fun iOS games using Swift, then this book is for you. You should be familiar with basic programming concepts such as classes, types, and functions. However, no prior game development or Apple ecosystem experience is required. Additionally, experienced game programmers will find this book useful as they transition into game development with Swift.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The game invokes the didMoveToView function whenever it switches to this scene."

A block of code is set as follows:

let mySprite = SKSpriteNode(color: UIColor.blueColor(), size: 
    CGSize(width: 50, height: 50))
mySprite.position = CGPoint(x: 300, y: 300)
self.addChild(mySprite)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    // Find the width of one-third of the children nodes
 jumpWidth = tileSize.width * floor(tileCount / 3)
}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Select iOS | Application in the left pane, and Game in the right pane."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Additionally, each chapter provides checkpoint links you can use to download the example project to that point.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/0531OT_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.