SpriteKit is a 2D Game Engine developed by Apple. It provides high level APIs and a wide range of functionalities to developers. It also contains an internal Physics Engine.
It is available on every Apple platform
Note: If you wish to develop using 3D graphics you need to use SceneKit instead.
The core building blocks of SpriteKit are:
Other related building blocks are:
An SKView is a subclass of UIView that is used to present SpriteKit 2D animations.
An SKView can be added to Interface Builder or programatically in the same way as 'normal' UIViews. SpriteKit content is then presented in the SKView in an SKScene.
See also SKView Class Reference from Apple Documentation.
SKScene represents a single scene in a SpriteKit application. An SKScene is 'presented' into an SKView. SKSpriteNodes are added to the scene to implement the actual sprites.
Simple applications may have a single SKScene that contains all the SpriteKit content. More complex apps may have several SKScenes that are presented at different times (e.g. an opening scene to present the game options, a second scene to implement the game itself and a third scene to present the 'Game Over' results).
When should you use SKAction
s to perform timer functions? Almost always. The reason for this is because Sprite Kit
operates on an update interval, and the speed of this interval can be changed throughout the life time of the process using the speed
property. Scenes can also be paused as well. Since SKAction
s work inside the scene, when you alter these properties, there is no need to alter your time functions. If your scene is 0.5 seconds into the process, and you pause the scene, you do not need to stop any timers and retain that 0.5 second difference. It is given to you automatically, so that when you unpause, the remaining time continues.
When should you use NSTimer
s to perform timer functions? Whenever you have something that needs to be timed outside of the SKScene
environment, and also needs to be fired even when the scene is paused, or needs to fire at a constant rate even when the scene speed changes.
This is best used when working with both UIKit
controls and SpriteKit
controls. Since UIKit
has no idea about what goes on with SpriteKit
, NSTimer
s will fire regardless of the state of the SKScene
. An example would be we have a UILabel
that receives an update every second, and it needs data from inside your SKScene
.
The determinants of Sprite Kit collision and contact event processing are the relationship settings, created by you, of categoryBitMask
, collisionBitMask
and contactTestBitMask
for each of your interacting object types. By rationally setting these in service of your desired outcomes from contacts and collisions, you determine which types can collide and inform of contacts with others, and avoid undesired collision, contact and physics processing overhead.
For each type of 'entity' you can set all three:
categoryBitMask
: a category specific to this type of nodecollisionBitMask
: a collision differentiator, can be different from abovecontactTestBitMask
: a contact differentiator, can be different from both aboveThe general steps to implement collisions & contacts are: