Learn iOS with Examples, Code Snippets and Video Tutorials

Testing for Alternate Device-Specific SKS files

How to Test for Alternate, Device-Specific SKS files


Sprite Kit Scene files, or .SKS files, provide game developers an easy way to design their game visually without having to do everything with code. Of course it helps to be able to generate certain things at runtime, for example you might want to spawn 100 enemies in random locations. But more often than not, you’ll probably want to design your levels using an SKS file.

How to Test for Alternate Device-Specific SKS files

Ideally your game can just use one SKS file for all devices, but that isn’t always going to work. For example, you might want your game to be portrait for iOS devices (the iPhone and iPad) but if you want to create a tvOS version as well, portrait mode isn’t an option.  In which case it can be useful to check what device your game is running on, then use a completely different SKS file specific for that device family. This would mean you could arrange GUI elements in different places, or design completely different levels.

The trick to all this is checking if that SKS file exists before the SKScene transitions in. We’ll do that in function called checkIfSKSExists which takes in a String parameter. That parameter is the base file name of the SKS file. So for example, “GameScene”.   Then if we find an SKS file with the name of “GameScenePhone”, “GameScenePad” or  “GameSceneTV” we use it. Otherwise we just use the base name of the SKS file (one that doesn’t have any suffix).

Here’s how the entire GameViewController would work with this implemented. You can test it out by creating a Sprite Kit scene file named “GameScenePad.sks” and testing in the iPad Simulator.


Check out our premium Swift and Sprite Kit Tutorial content!

Visit CartoonSmart.com