Git Product home page Git Product logo

sktiledparser's Introduction

SKTiledParser

Overview

A simple parser that can creates Apple Spritekit's SKTileMapNode from a .tmx file (created in Tiled).

The whole project is written with Swift 3.

Motivation

Spritekit's SKTileMapNode is a nice addition to the Apple's framework, but I find Xcode's tile editor not as good as the largely more popular Tiled editor. I sought for a solution that would leverage SKTileMapNode while being able to import resources from Tiled, but failed to find something that suited my needs. As a result, I decided to rework Tom Linthwaite's SKTilemap project so that I could generate SKTileMapNode and SKTileSet from .tmx files.

Usage

Simply drag and drop SKTiledParser.swift to your project to import the code.

Then, create an instance of SKTiledParser, and load your .tmx file with loadLayout(fromFileNamed:). Each layer from your file will be transformed into an SKTileMapNode, and made children of a single "layout" the method will return. You can then access the root node of this layout to insert the tilemaps in your scene.

let parser = SKTiledParser()
let layout = parser.loadLayout(fromFileNamed: "tilemap")
scene.addChild(layout!.rootNode)

It will not only create the tilemap nodes, but also the SKTileSet from which the tiles will be displayed.

The Xcode project shows a working example.

Locating textures

The textures of the tilesets are read from your assets. Note that for that mechanism to work, tile images referenced within your .tmx file are expected to be named after your assets name. Only the base name of the file (without extension) matters.

For instance, let's say I defined two image sets in my asset catalog, named grass and rock. Then Tiled should reference them by files respectively named path/to/somewhere/grass.png and path/to/somewhere/rock.png (the extension doesn't matter, it could very well be .jpg instead)

Since the texture lookup is done by SKTexture.init(imageNamed:), you can seamlessly use sprite atlases.

The most convenient setup is to first generate your sprite atlases, and then create your tilesets in Tiled using references to the files in your asset catalog.

Finally, if like me you like to keep your things tidy in you asset catalog, you can use namespaces. Initialize SKTiledParser with init(texturesNamespace:) to specify the namespace that should be prepended when searching for textures.

sktiledparser's People

Contributors

kyouko-taiga avatar

Stargazers

 avatar Jonathan Pappas avatar  avatar Sha Senevirathne avatar  avatar David Fischer avatar Jared avatar Kim Pedersen avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.