1
\$\begingroup\$

I'm writing an original (top-down) SimCity clone in Swift and attempting to use SpriteKit as the basis for the game. However, I am running into performance issues when rendering and animating the tile map which represents the city map.

I'm rendering a 44x44 tile map with each tile being 16x16 pixels. Tile animation could happen on any arbitrary tile and is implemented by having a separate image for each frame of the animation. The map is dynamic (naturally) since the player will draw on it and tiles can be animated (roads, etc). I have tried several implementations to render the map the screen and each has had its own performance issues.

What I've tried:

  • Each tile is an SKSpriteNode with its texture loaded from a texture atlas. Textures were swapped for tiles that were dirty (needed redraw). I disabled physics simulations and physics bodies on the nodes.
    • Pros:
      • Minimal draws (due to the Texture atlas)
      • Code wasn't very complex
    • Cons:
      • Redrawing the entire map destroyed performance
      • Swapping textures to animate was inefficient
  • Map was rendered using NSView, drawRect, etc.
    • Pros:
      • Drawing was relatively efficient
      • Dirty rectangle drawing was easy to implement
    • Cons
      • Not really suitable for animation (really bad performance)

My question is: What is the most efficient way of rendering/animating my tile map? Is there an optimization I can make to SpriteKit to speed this up? Or do I need to use something lower level (OpenGL/GLSL) to draw/animate the map efficiently?

Any help would be greatly appreciated!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.