Skip to content

Getting Started

Michael Fessenden edited this page Sep 21, 2017 · 6 revisions

SKTiled was designed to be flexible and easy to use. To get started, simply build the framework and add your assets to your Xcode project. If you have any problems or requests, please open an issue at the Github page.

Requirements

  • iOS9+/macOS 10.12+
  • Xcode 9
  • Swift 3.2

Swift 4

For use with Swift 4, please check out the Swift 4 branch.

Installation

The SKTiled project contains four targets; two are demo applications for iOS & macOS. These are included to let you quickly test your own content, or simple play around with the included demo files. The other two are frameworks for use in your own projects.

Project Schemes

To use the frameworks, build one or both of the targets and add them to your project. Make sure the Minimum Deployment Target is set correctly for your project (iOS9+/macOS 10.12+).

Framework Installation

adding framework

After building the framework(s), you'll need to add them to your project. Select your target, and add the framework to the Embedded Binaries and Linked Frameworks and Libraries sections of the General tab. You'll also need to make sure it is linked in the Build Phases > Embed Frameworks section.

framework linking

framework embed

Carthage Installation

To build with Carthage, create a Cartfile in your project root and add a reference to SKTiled (be sure to check the current version number):

github "mfessenden/SKTiled" ~> 1.16

Close the file and run Carthage from the terminal to build the framework(s):

carthage update

To build for a specific platform, use the platform argument in your build command:

carthage update --platform iOS

Once you've run the build command frameworks are built, you'll find a Carthage directory in the root of your project. The frameworks are located in the Carthage/Build/$PLATFORM_NAME directories, simply install them as described in the framework installation section above.

Carthage Directories

See the Carthage home page for help and additional build instructions.

CocoaPods Installation

Installation with CocoaPods is similar to Carthage. Create a podfile in your project root with the command:

pod init

Add references to SKTiled in each of your targets:

target 'iOS' do
  use_frameworks!

  # Pods for iOS
  pod 'SKTiled', '~> 1.16'

end

target 'macOS' do
  use_frameworks!

  # Pods for macOS
  pod 'SKTiled', '~> 1.16'

end

As before, be sure to check the version number. In the terminal, run the installer:

pod install

CocoaPods will create an .xcworkspace file with the name of your project. Open that and use this to compile your targets; dependencies will be linked automatically.

See the CocoaPods home page for help and additional instructions.

Building with Xcode 8

Xcode 8 requires zlib to be linked to the project. Add a link to the zlib directory for all targets:

Project > Build Settings > Swift Compiler - Search Paths > Import Paths

Linking zlib

Adding Tiled Assets to Xcode

Grouped Assets

When adding assets to your Xcode project, files are automatically bundled in your application. To load a bundled tile map, use the SKTilemap.load method to read the file:

if let tilemap = SKTilemap.load(tmxFile: "MyTilemap.tmx") {
    scene.addChild(tilemap)
}

On your hard drive, the map's tileset and image should be in the same directory as the map to avoid read errors.

Referenced Assets

Referenced Assets

If you add assets as folder references, you can supply a directory name with the inDirectory argument of SKTilemap.load method:

if let tilemap = SKTilemap.load(tmxFile: "MyTilemap.tmx", inDirectory: "Tiled") {
    scene.addChild(tilemap)
}

This will allow you more flexibility organizing your project, but be careful that your maps don't reference files above the referenced folder.