When the iOS 8 platform was launched by Apple, the SpriteKit framework received quite a few new features – geared to make the tool more developer-friendly. In what follows, some of these new SpriteKit features have been listed.
Released with iOS 7, SpriteKit has fast become the preferred mobile game development tool for many developers across the globe. According to reports, its popularity has already started to rival that of Cocos2D. The fact that SpriteKit is a native Apple framework has been an advantage too. On the iOS 8 platform, several new features have been added to SpriteKit – much to the delight of mobile game developers. We will here highlight some interesting new additions to SpriteKit on iOS 8:
- Integration with SceneKit – Apple finally brought the Objective-C-based SceneKit tool to its mobile platform – SceneKit – with iOS 8. Game development experts now have the option of using this tool to add 3D content in applications created with SpriteKit. A SK3DNode object has to be declared, which would serve as the root for the app/game scene. The three-dimensional content gets rendered directly within the SpriteKit pipeline, and coders can manage them just as general SKNode instances. The overall hierarchy becomes something like: SK3DNode → SCNScene → SCNNode → SCNLight/SCNCamera/SCNGeometry. Of course, SceneKit can be used on a standalone basis as well.
- Enhanced physics support – SpriteKit on iOS 8 offers delightful game physics support. The SKFieldNode, which is used to include physics fields, can be combined with an array of diverse factory methods. Radial gravity fields (SKFieldNode.CreateRadiaGravityField() ), Spring Fields (SKFieldNode.CreateSpringField() ), and radial vortexes are some instances of the new physics fields that can be created with SpriteKit. With the same SKFieldNode class, iOS app development experts can tweak around various field properties, like region, strength, and field force attenuation.
- Compatibility with OpenGL ES – Prior to the release of iOS 8, there were no provisions of accessing the OpenGL ES framework directly from SpriteKit. Apple has changed things around with its latest mobile platform, by introducing greater support for the built-in fragment shaders in OpenGL ES. The SpriteKit tool had been released in the first place to provide iPhone game developers an engine on top of OpenGL, and with iOS 8, collaboration between the two tools has become seamless.
- From Textures to Physics Bodies – This is a breakthrough feature of SpriteKit, added in the new version. While creating 2D/2.5D iOS games, developers can now derive physics bodies of sprites from their respective textures. The extra coding required for this only involves calling SKPhysicsBody.Create (i.e., sprite.PhysicsBody = SKPhysicsBody.Create () ). Note that, the size and the texture attributes have to be present inside SKPhysicsBody.Create. With the help of this new feature, game animators can now make clashes and collisions in their game interfaces appear much more realistic than before.
- Customized Shaders and Effects – Apart from supporting the fragment shaders of OpenGL ES, SpriteKit on iOS 8 comes with a variety of other shaders for screen customization. Since the required coding for implementing shaders has significant similarities with Objective-C, proficiency with that programming language is essential (then of course, you cannot start using SpriteKit without knowing Obj-C, right?). Since the shader effects are applied in the per-pixel method, they appear that much more detailed and engaging. After creating a ‘ShaderSceneEditor’ in the ‘SpriteKit Scene’ (under File → New → Resource), game developers need to navigate to ‘SKNodeInspector’, and set the Gravity and Size parameters. This will add the desired shader effect to the game scene.
- Magnetic Fields – Another newly-added feature in SpriteKit that helps iPhone app and game developers add more realism to their software. The Magnetic Fields are all about ensuring that, in a scene, all the nodes would be under a virtual gravitational effect and would be pulled in a downward direction. Both the strength and the position of the magneticFieldNode have to be configured, and coders have to add a separate SKPhysicsBody instance under didMoveToView: (to implement the gravitation pull). The magneticFieldNode instance variable, of course, is created in PhysicsScene.m. All new magnetic field nodes are added as ‘child nodes’ to the SpriteKit scene.
- Displaying physics field effects in sprites – Professionals from the field of mobile game development correctly point out that many of the new features of SpriteKit are related to its physics properties. Here’s another of them: developers can now add the effect of the same or different force fields on a sprite. A ‘public override void TouchesBegan’ class has to be added for the former. Whenever players touch the game screen/specific objects, the physics field effects are displayed (for example, radial movement of a character). A sprite can also be influenced by a different physics field by declaring a ‘SKFieldNode fieldNode’, and specifying the ‘fieldNode.Enabled’ option as ‘True’. Remember to add the other properties (falloff, position, strength, etc.) of the fieldNode as well.
- More lights for games – Game illumination can be made more personalized than ever before with SpriteKit in iOS 8. To make their iOS games more visually appealing, as many as 8 different lighting effects can be added to every sprite. Inside the LightingSceneEditor.sks, there is a well-stacked Media Library – with a host of resources that can be added to game interfaces (including ‘Shadows’). While configuring the light and shadow, developers have to first set the Node’s Z-Position to ‘1’, and then set the properties/values for ‘Ambient’, ‘Shadow’ and ‘Color’. Each property of the sprite nodes are matched with the ‘categorybitMask’ light property (this happens during the scene rendering) – and whenever the properties are in sync, the lighting/shadow effects are displayed on that particular sprite. In SKNodeInspector, the background has to be updated – otherwise the light won’t illuminate the background.
- Calculating Inverse Kinematics – The objects in SpriteKit games can now be made more geometrically accurate by iOS developers – thanks to the new Inverse Kinematics (IK) functionality. In the joint hierarchy in SpriteKit (with parent nodes and child nodes), the final points of any structure is given – and based on its position, coders can calculate the angles at which the other joints have to be present. The max. and min. rotation angles between joints is specified via the constraints specified for each of them. Since all the joints are moved around their respective ‘anchor points’, the overall structure remains systematic. Inverse Kinematics can be implemented directly from the PhysicsSceneEditor, and after selecting the target sprite(s) from SKNodeInspector.
- Getting real time feedback on shaders – Not only has Apple really revamped the shaders in SpriteKit on iOS 8, it has also made the chances of errors remaining undetected minimal. While coding the shaders, game developers can check real-time feedback (within the Xcode environment). Since alerts are generated as soon as any potential shader errors are detected, developers need not wait till the actual deployment of their games on simulators/devices to find out bugs (if any). The overall mobile app testing procedure also becomes a touch easier. To get the runtime feedback, coders have to configure the Assistant Editor in a manner that, both the new shader as well as the SpriteKit scene are visible.
- New set of Constraints – A new range of physics field constraints have also been added to the SpriteKit tool. The properties of every single sprite node can be altered by adding constraints to them. To specify constraints, you have to be in the ‘Edit’ mode and set values for IK Constraints Max and Anchor Point X. Once this is done, you can check out the effects of the specified constraints under the ‘Simulate’ mode. In addition, there are options to manually change the properties (size, position) of the sprite nodes.
- Including Custom Shaders – Ever since SpriteKit custom shaders were showcased by Apple at last year’s WWDC, they have been a focal point of interest for all iPhone/iPad game development experts. Adding these shaders is simple enough – an empty source file has to be created, and from ‘iOS’, the Other → Empty option has to be chosen. After that, a small block of code has to be written, to add a custom shader. Alternatively, shaders can also be added by detecting the tap-position of users on the game screen, and putting a custom SKSpriteNode there. Following each tap, a new sprite (the type depends on your specifications) gets added – with custom shaders and modified textures.
The option of adding Color Sprites is yet another nice addition to the Lighting features of SpriteKit in iOS 8. With the help of the SpriteKit-SceneKit integration, game developers can check out live previews as well as import external models. It is advisable to start off working with SpriteKit on the latest stable iterations of Xcode (Xcode 6.3) and iOS 8 (8.3). The new features in the game engine indeed make the tool more exciting and developer-friendly.
Latest posts by Hussain Fakhruddin (see all)
- Data Protection 101: 3 Important Strategies To Make A Secure App - July 19, 2019
- Software vs Humans: The Pros and Cons of Online App Builders - July 18, 2019
- Do SaaS Companies Need Mobile Apps? Oh Yes, And Here’s Why - July 16, 2019