Tutorial: Introduction to SpriteKit in Swift

(Image courtesy developer.apple.com)
This is an introduction to a series of SpriteKit tutorials written in the Swift programming language. (We will release the entire series over the course of several weeks). At the top level, this tutorial will be broken up into seven sections. Each section will be comprised of several lessons. For our first section we will focus on the fundamental techniques for working with SpriteKit content. Since sprites are the fundamental building blocks used to create the majority of a games scene’s content we will look at that next. We will then learn how to apply actions to sprites to be able to move around in a game scene. In section four we will expand on the basic concepts just learned by delving deeper into the concept of a node tree and ways to build our game scenes. We will then look at advanced scene processing techniques. In the sixth section we will learn how to simulate physics on the bodies within our scenes. And lastly we will discuss SpriteKit best practices.

Target Audience
We assume that you are already familiar with the fundamentals of app development. You should know how to develop apps using Xcode with Objective-C or Swift programming language, be familiar with blocks or closures and possess an understanding of views and windows as they relate to app development. If you are not familiar with these concepts then we suggest you visit our online learning page and go through some of our Swift programming tutorial before continuing.

SpriteKit Overview
SpriteKit is a graphics rendering and animation framework that comes with a set of tools for animating textured images, or sprites and special effects. SpriteKit conforms to the traditional rendering loop of first processing the content before the frame is rendered. This process of rendering frames is efficient because the work is executed using the graphics hardware (GPU) as opposed to using the CPU. This means that when we position sprites we can arbitrarily do so in each frame of animation without generally needing to worry about time or space complexity. In a nutshell, SpriteKit is a cross-platform (OSX and iOS), efficient and fully optimized game engine.

For the remainder of this introduction we will briefly describe some of the components used to make games. In future tutorial we will explore these and other components in greater detail.
Drawing Canvas
An SKView is an object that is responsible for animating and rendering your content once it is placed inside a window object. You may combine the content of this view object with other views that are in the same view hierarchy.

Canvas Content
SpriteKit supports different types of content that include the following:
  1.  Textured or untextured sprites. Sprites are bitmap objects that are drawn on a screen. Texturing is the processes of adding bitmap image(s) to a sprite so that our games "feel" and look lifelike.
  2. Text
  3. CGPath-based shapes. Similar to sprites, CGPath-based shapes are drawn to a screen using points, lines or arcs and may be filled with solid or gradient colors. 
  4. You may also embed video content in a game scene.
Game Scene
An SKScene is an object designed to organize the various sprites and other content within a game. Your game will present one scene at any given time. The processing logic that updates a scene on a per-frame basis will live within this object.

Game Scene Transitions
An SKTransition is an object used for transitioning between multiple SKScene objects when using a single SKView. This object provides default scene transition behavior.

Building Block
The fundamental building block of SpriteKit content are comprised of SKNode objects. These objects come with default behavior that is shared among other node objects. The SKNode class does not draw anything, but instead holds an objects position in a given coordinate system and applies any properties, like rotation, to its content and to the content of its descendants. These descendant relations of nodes are defined by their position in a tree like structure with the scene object acting as the root node. Another benefit to using the SKNode class is that it handles application events like touches. Default event handling by SKNode objects is possible because it is a subclass of the UIResponder class.

Game Action
Animation of content is achieved with the use of SKAction objects. You would generally use actions to move, scale, rotate or animate the transparency of a node. Scenes can also take advantage of these action objects.

Game Physics
SpriteKit comes with a set of objects that define how node objects interact during a collision, under the influence of gravity or in a river stream. These physics objects will speed up your game development by shifting your focus on game dynamics and user interactions instead of getting bogged down with formulating and managing physics equations. To take advantage of these physics objects, you create SKPhysicsBody object and attach them to the nodes in your scene. You can also apply gravity to all, (or some with the use of SKFieldNode), object nodes in your scene by creating a SKPhysicsWorld object and attach it to your scene. If your game includes an animating train, then you can connect the train cars with an SKPhysicsJoint object and simply move the lead car to give it a super real effect.

This concludes our introduction to SpriteKit. After reading this I hope that you are convinced that SpriteKit offers a set of tools that will help you build games comparable to that of a midsize game shop but with the use of third party tools. If you are not convinced, then stay tuned because SpriteKit offers so much more.

In our next blog post we will write code with a focus on the fundamental techniques for working with SpriteKit content.

This tutorial is based on Apple's SpriteKit Programming Guide.


  1. This comment has been removed by the author.

    1. Great Article Cloud Computing Projects

      Networking Projects

      Final Year Projects for CSE

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Most of the students can’t take a daily classes and professor lectures and the other side some students can’t get admission in any academic or university because they live distant from higher education institutes. But now education is everywhere and easy to learn, online education has many courses and fast online degrees program for all students.

  3. Replies
    1. Like!! Thank you for publishing this awesome article.

  4. Really nice introduction to the language.Loved it.
    It was a pleasure reading your article.
    Hope to read more from you.
    To learn another hot and awesome language give myTectra a try.
    myTectra is the Marketing Leader In Banglore Which won Awards on 2015, 2016, 2017 for best training in Bangalore:
    python interview questions

    python online training

  5. very helpfull blog it was a pleasure reading your blog
    would love to read it more
    knowldege is not found but earned through hardwork and good teaching
    that being said click here to join us the next best thing in bangalore
    devops online training
    Devops Training in Bangalore

    1. Like!! Thank you for publishing this awesome article.

  6. We Offer all types of Finance Business Personal Cash
    Quick Cash Advance. Fast Credit Check. Cash Today.
    Fast Cash Online
    low interest rate as low as 2%
    Financial Cash Available Here
    Business Personal Cash
    I'll advise All Cash seeker should contact us
    Contact Us At : abdullahibrahimlender@gmail.com
    whatspp Number +918929490461
    Mr Abdullah Ibrahim

  7. Thanks for all the tips mentioned in this article! it’s always good to read things you have heard before and are implementing, but from a different perspective, always pick up some extra bits of information. Visit@
    QuickBooks Support

  8. feeling good to visit your site actually most of people do lot of work but dont share their experience
    others Gaming Site
    that may be helpful for others to complete quests and find hidden places in different games
    conflux lost sector
    I help out most of people like as you are doing, I appreciate your work well done.

  9. wow wonderful information i really appreciate it what about the mod apk

  10. Like!! Thank you for publishing this awesome article.