• Unlikely Objects
  • Ludography
    • Nonoku
    • Acquisition
    • Image Mark Up
  • About
Menu

Unlikely Objects

  • Unlikely Objects
  • Ludography
  • Pint Sized Planet
    • Nonoku
    • Acquisition
    • Image Mark Up
  • About

Nonoku - First Steps With SpriteKit

November 16, 2016

I’ve not had an excuse, up to now, to play with SpriteKit. Initially I was going to re-write Nonoku following the same basic implementation as I did before with custom UIView elements. Whilst walking back from lunch, I wondered if I could come up with something that wouldn’t stretch my limited artistic abilities but still look nice. Adding a little more motion to it would be good but that wouldn’t really fit with UIView and autolayout. So, I decided to give SpriteKit another look.

I’d taken a glance at it before but not in any real depth and I was pretty sure I’d missed some stuff in just following tutorials.

So, first step, get an SKView in my GameViewController class. Easy enough, I’m using a storyboard so just change the class of the View belonging to the UIViewController to an SKView. It’s still a UIView when referencing it in code so I need to remember to cast it when using it: view as! SKView.

override func viewDidLoad() {
        super.viewDidLoad()
        let spriteView = view as! SKView
        spriteView.showsFPS = true
        spriteView.showsDrawCount = true
        spriteView.showsNodeCount = true
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let gameScene = GameScene(size: view.bounds.size)
        let spriteView = view as! SKView
        spriteView.presentScene(gameScene)
    }

Easy enough. I also need something to show so I included a GameScene object. This is just a starting point so I’ll start with drawing the board the tiles will be displayed on.

The board is a rounded rectangle, divided into a 10x10 grid by dashed lines. Since I don’t expect this to change I added the board outline, and the lines, to an SKEffectNode with shouldRasterize set to true. This means it will render itself to a cached bitmap so it can be re-rendered quickly, instead of re-drawing each node every frame. The number of draw calls dropped from 20, to 1, with this change. Whilst optimising upfront is normally to be avoided, this is a small change and easily reversed. More importantly, it’s something to be remembered later. Considering how multiple items can be grouped together can bring noticeable performance improvements.

In An Evening of Code Tags iOS, Pint Sized Planet, nonoku, indiedev
← Nonoku - Adding Some ColorNonoku - The Rewrite →

Latest

Unlikely Objects
Fractal Plant in Godot
about a year ago
Binary Tree in Godot
about a year ago
Sierpinski Triangle in Godot
about a year ago
Re-visiting some old code
about a year ago
React - Starting a New Project
about 3 years ago
Satsuma Tosser
about 4 years ago
1HGJ #002: Deeper and Deeper
about 7 years ago
1HGJ #001: Telekinetic Bomberman Rush
about 7 years ago
Migrating to NSPersistentContainer
about 7 years ago
Nonoku - SpriteKit Shader
about 7 years ago

Powered by Squarespace