Book Image

Learning iOS 8 Game Development Using Swift

By : Siddharth Shekar
Book Image

Learning iOS 8 Game Development Using Swift

By: Siddharth Shekar

Overview of this book

<p>Game development has been simplified with Apple's new programming language—Swift. If you're looking to start learning iOS development then you'll get everything you need - from&nbsp;the absolute basics such as the Xcode interface and takes you all the way to Swift programming.</p> <p>You will take a walk through the creation of 2D and 3D games followed by an introduction to SpriteKit and SceneKit. The book also looks at how game objects are placed in 3D scenes, how to use the graphics pipeline, and how objects are displayed on mobile screens. You will also delve into essential game concepts such as collision detection, animation, particle systems, and scene transitions. Finally, you will learn how to publish and distribute games to the iTunes store.</p>
Table of Contents (18 chapters)
Learning iOS 8 Game Development Using Swift
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

2D and 3D coordinate systems


In the case of 2D game development, we have only two coordinate systems to worry about. The first is the screen coordinate system, and the other is the object coordinate system.

In 2D, whenever we place an object on the screen, we always wonder how far the object is from the bottom-left corner of the screen. This is because the bottom-left corner of the screen, and not the center of screen, is the origin. Therefore, if you place a sprite without changing its position, it will be created in the bottom-left part of the screen. The screen origin or the (0, 0) position is in the bottom-left corner of the screen. If you want to place the sprite in the center of the screen, you need to add half the width and height to the position property, since everything is in respect to the bottom-left corner of the screen. This is called the Screen Coordinate system.

The object coordinate system refers to the sprite itself. The center of the sprite is at the center of the object, unlike the screen, which has its origin at the bottom-left corner. The center of the sprite is called the anchor point. When you rotate a sprite, it will rotate about its center because its origin is at its center. You can change the origin of the sprite by accessing its Anchor Point property.

In 3D game development, there are a couple of more coordinate systems. So, there are the World, Object, View, and Screen coordinate systems. Other than being referred to as Coordinate Systems, they are also referred to as a space.

In the case of 2D, the World Coordinate system is the same as the Screen Coordinate System, but in 3D that is not the case. In the following diagram, imagine you are seeing the jet on your device:

The World space's origin is where the red, green, and yellow arrows originate from. The red arrow represents the positive x axis, green is the positive y axis, and yellow is the positive z axis. The World space's origin is at 0, 0, 0.

The jet is placed within the World space. As with the sprite, the Object Coordinate System is at the center of the object.

The red box represents a camera looking towards the jet plane. The place where the camera is positioned is called a view, eye, or camera coordinate system. The view frustum represents the view limits of the camera. Anything placed outside this area won't be rendered by the camera. In graphics programming, this is called clipping.

Finally, whatever is seen by the camera has to be projected onto the screen of the device. This is called the Screen Coordinate System.