Import TilePix Maps into SpriteKit (Swift)

A practical guide to loading TilePix tilemaps into iOS and macOS games using SpriteKit and Swift.

⏱ 5 min read Game Development / Swift

Contents

Overview

If you're using TilePix to design your 2D game levels, you can easily load the exported ZIP archive (which contains your single or multi-layered JSON map data and PNG tileset) directly into your iOS or macOS game.

Below is a complete, ready-to-use Swift script using SwiftUI, SpriteKit, and ZIPFoundation to automatically parse the JSON and build a layered SKTileMapNode.

What You Get from TilePix

  • ZIP archive with JSON map data
  • PNG tileset image sheet
  • Layer-based tilemap structure
  • Engine-ready export format

Requirements

  • Swift 5+
  • SpriteKit framework
  • ZIPFoundation (GitHub)

Prerequisites (TilePix Export Setup)

  • Add the ZIPFoundation library to your Xcode project via Swift Package Manager.
  • Export your project from TilePix as a ZIP file, name it archive.zip, and drag it into your Xcode project bundle.

Code Implementation (SpriteKit + TilePix)

import SwiftUI
import SpriteKit
import ZIPFoundation

struct GameProject: Codable {
    let id: String
    let maps: [GameMap]
    let tilesets: [Tileset]
}

struct Tileset: Codable {
    let id: String
    let name: String
    let tileWidth: Int
    let tileHeight: Int
    let grid: Grid
}

struct Grid: Codable {
    let width: Int
    let height: Int
}

struct GameMap: Codable {
    let id: String
    let name: String
    let layers: [MapLayer]
    let mapWidthInTiles: Int
    let mapHeightInTiles: Int
    let associatedTilesetID: String
}

struct MapLayer: Codable {
    let id: String
    let name: String?
    let tileData: [Int]
    let isVisible: Bool?
}

class GameScene: SKScene {
    private let cameraNode = SKCameraNode()
    private var mapContainer = SKNode()

    private var project: GameProject?

    override func didMove(to view: SKView) {
        addChild(mapContainer)
        addChild(cameraNode)
        camera = cameraNode

        if let url = Bundle.main.url(forResource: "archive", withExtension: "zip") {
            loadProjectFromZip(url: url)
        }
    }

    func loadProjectFromZip(url: URL) {
        guard let archive = Archive(url: url, accessMode: .read) else { return }

        guard let jsonEntry = archive.first(where: {
            $0.path.hasSuffix(".json")
        }) else { return }

        var jsonData = Data()
        _ = try? archive.extract(jsonEntry) { jsonData.append($0) }

        project = try? JSONDecoder().decode(GameProject.self, from: jsonData)

        guard let imgEntry = archive.first(where: {
            $0.path.hasSuffix(".png")
        }) else { return }

        var imgData = Data()
        _ = try? archive.extract(imgEntry) { imgData.append($0) }

        guard let uiImage = UIImage(data: imgData) else { return }

        let texture = SKTexture(image: uiImage)
        texture.filteringMode = .nearest
    }
}

Preview:

SpriteKit map imported from TilePix

Why This Works Well

Performance

SpriteKit handles tile rendering efficiently using GPU acceleration.

Pixel Accuracy

Nearest-neighbour filtering keeps retro visuals sharp.

Workflow

TilePix exports are structured specifically for game engines.

Scalability

Supports multi-layer tilemaps for complex levels.

Build Your Game Faster with TilePix

Design visually in TilePix and export directly into SpriteKit without manual tilemap work.

Download TilePix