Improving SpriteKit performance with optimized Textures

David Piper
2 min readSep 15, 2019

--

Working on a SpriteKit game for iOS can have some hidden challenges, one of them being performance issues which can be hard to track down. Currently I am creating a small game together with my wife and we encountered sudden and spontaneous fps drops. After some investigating and reading, we found a great list of possible reasons in this article by Paul Hudson.

He proposes multiple improvements we can apply to our game, e.g.

  • using texture atlases instead of multiple single pictures
  • preloading textures and
  • orienting the assets the same way they will be used in the game instead of rotating a single texture in code.

In our game the player is a fish which can face four different directions as you can see in the image below.

A player can face four different directions.

Previously we used one texture and its mirrored version, which were rotated to the correct direction in code. But as Paul wrote, this calculated rotation leads to more work in each render loop, which resulted in visible frame drops. Thus we decided to make a texture for each direction the fish could face. As we had not just one version of the fish but more than 15 different skins a user could choose from, we did not want to prepare each single one by hand. So I wrote a small python script, which creates all needed images from one fish. It also creates a directory with a “.atlas” extension and saves all images in it. This enables us to use all images for one version of the fish as one texture atlas in Xcode.

This was a great example, where a really small python script could perfectly automate a repetitive task. It can be found on my GitHub site.

--

--

David Piper
David Piper

Written by David Piper

Working as an iOS and Android dev.

No responses yet