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

The colored quad project


To create a colored square, we need to make some changes to vertexArray, as we will need to pass six vertices instead of three. We have to pass six vertices because, as you saw earlier, we can draw only in triangles. So, we need three points for the triangle to form the top part of the square and three more points to form its bottom part:

let vertexArray:[Float] = [

    -1.0, 1.0, 0, 1,  //a
    -1.0, -1.0, 0, 1, //b
    1.0, -1.0, 0, 1,  //c    
    -1.0, 1.0, 0, 1,  //a
    1.0, -1.0, 0, 1,  //c
    1.0, 1.0, 0, 1,   //d
]

You will see that the a and c points are repeated to form the second triangle, because the diagonal of the square are the same points for the first triangle.

Notice that in the vertex array, we are now passing four values per vertex instead of two, as we did in the case of the triangle. This will simplify matters while modifying the shader function.

The values of the coordinates provided are the x, y, and z values, and an additional fourth parameter...