All Projects → mfessenden → Sktiled

mfessenden / Sktiled

Licence: other
Swift framework for working with Tiled assets in SpriteKit

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Sktiled

Legend Wings
iOS Swift Game - Push SpriteKit to the limit
Stars: ✭ 481 (+131.25%)
Mutual labels:  game-development, spritekit
Glide
Game engine for making 2d games on iOS, macOS and tvOS, with practical examples and tutorials
Stars: ✭ 353 (+69.71%)
Mutual labels:  game-development, spritekit
Octopuskit
2D ECS game engine in 100% Swift + SwiftUI for iOS, macOS, tvOS
Stars: ✭ 246 (+18.27%)
Mutual labels:  game-development, spritekit
Flappy Fly Bird
🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].
Stars: ✭ 150 (-27.88%)
Mutual labels:  game-development, spritekit
Methanekit
🎲 Modern 3D graphics made simple with cross-platform C++17 meta-API on top of DirectX 12 & Metal (Vulkan is coming)
Stars: ✭ 197 (-5.29%)
Mutual labels:  game-development
Open Match
Flexible, extensible, and scalable video game matchmaking.
Stars: ✭ 2,404 (+1055.77%)
Mutual labels:  game-development
Hge
HGE 1.9 configured with CMake DirectX9 version, with shaders. The classic 1.8.1. version is in the `master` branch if you ever need that.
Stars: ✭ 185 (-11.06%)
Mutual labels:  game-development
Cocosocket
cocosocket是一个为高性能网络通信准备的底层通信框架,满足对于高性能网络通信的需求,适用于基于tcp或kcp的应用开发。
Stars: ✭ 182 (-12.5%)
Mutual labels:  game-development
Vulkan Renderer
A new 3D game engine using modern C++ and Vulkan API
Stars: ✭ 205 (-1.44%)
Mutual labels:  game-development
Delight
Delight is an open source component-oriented framework for Unity.
Stars: ✭ 201 (-3.37%)
Mutual labels:  game-development
Godot Kickstarter 2019
Create your Own Games with Godot, the Free Game Engine: sources from the January Kickstarter project from GDQuest
Stars: ✭ 194 (-6.73%)
Mutual labels:  game-development
Arcadecarphysics
Arcade Car Physics - Vehicle Simulation for Unity3D
Stars: ✭ 189 (-9.13%)
Mutual labels:  game-development
Xdpw
XD Pascal: A small embeddable self-hosting Pascal compiler for Windows. Supports Go-style methods and interfaces
Stars: ✭ 199 (-4.33%)
Mutual labels:  game-development
Deadsimple Pixel Perfect Camera
An exceedingly easy-to-use pixel perfect orthographic camera script for 2D scenes in Unity. Punch in a few specs and you've got a working pixel perfect camera. It's that easy.
Stars: ✭ 186 (-10.58%)
Mutual labels:  game-development
Krita Batch Exporter
A Free Krita plugin to batch export layers and groups with maximum flexibility. Scale, trim, export multiple copies of your layers...
Stars: ✭ 201 (-3.37%)
Mutual labels:  game-development
Hitagi.js
JavaScript HTML5 game development framework
Stars: ✭ 184 (-11.54%)
Mutual labels:  game-development
Ez Camera Shake Unity
A free powerful asset for achieving easy and quality camera shake in Unity. Open-sourced with the permission of Road Turtle Games. 📷
Stars: ✭ 191 (-8.17%)
Mutual labels:  game-development
Unity Shaders
✨ Shader demo - More than 300 examples
Stars: ✭ 198 (-4.81%)
Mutual labels:  game-development
Debroglie
DeBroglie is a C# library implementing the Wave Function Collapse algorithm with support for additional non-local constraints, and other useful features.
Stars: ✭ 190 (-8.65%)
Mutual labels:  game-development
Engine
Cocos Creator is a complete package of game development tools and workflow, including a game engine, resource management, scene editing, game preview, debug and publish one project to multiple platforms.
Stars: ✭ 2,574 (+1137.5%)
Mutual labels:  game-development

SKTiled

SKTiled is a framework for integrating Tiled assets with Apple's SpriteKit, built from the ground up with Swift. This project began life as an exercise to learn Apple's new programming language for a game project, but I've decided to release it as open source with the hopes that others will find it useful. SKTiled is up-to-date and supports Tiled's major features, including all map & object types.

Demo Image

Check out the Official Documentation.

Features

  • [x] iOS & macOS versions
  • [x] tvOS version
  • [x] parses inline & external tilesets
  • [x] translates custom properties for maps, layers, objects & tiles
  • [x] renders all projections: (orthogonal, isometric, hexagonal & isometric staggered)
  • [x] renders all layer types: (tile, object, image, group)
  • [x] supports all compression types: (base64, zlib, gzip)
  • [x] renders animated and flipped tiles
  • [x] pre-loading of tilesets
  • [x] group nodes
  • [x] tile objects
  • [x] text objects
  • [x] template objects
  • [x] custom tile & object classes
  • [x] generate GKGridGraph graphs from custom attributes
  • [x] user-definable cost properties for GKGridGraph nodes
  • [ ] infinite maps
  • [ ] tile collision objects
  • [ ] Zstandard compression support

Requirements

  • iOS 12
  • tvOS 12
  • macOS 10.12
  • Xcode 11/Swift 5

Installation

Carthage & CocoaPods Support

For Carthage installation, create a Cartfile in the root of your project:

github "mfessenden/SKTiled" ~> 1.22

For CocoaPods, install via a reference in your podfile:

pod 'SKTiled', '~> 1.22'

Usage

Loading a tilemap is very straightforward:

if let tilemap = SKTilemap.load(tmxFile: "sample-map") {
    scene.addChild(tilemap)
}

Once loaded, the rendered SKTilemap node reflects the various properties defined in the originating scene:

  • SKTilemap.size: size of the map in tiles.
  • SKTilemap.tileSize: size of individual tiles.
  • SKTilemap.orientation: map orientation (ie orthogonal, isometric, etc).

The SKTilemap node also gives users access to child layers, tilesets, objects or individual tiles.

Working with Layers

Layers represent containers that hold various types of data:

  • tile layers hold an array of tile sprites and associated tileset data
  • object groups contain vector shape objects
  • image layers display a single image

All SKTiled layer types are subclasses of the base SKTiledLayerObject object and provide access to coordinate transformation and positioning information. Additionally, every layer type can have individual offset transforms and rendering flags.

Layers can be accessed by type, name or index:

// query layers by type
let tileLayers = tilemap.tileLayers
let objectGroups = tilemap.objectGroups
let imageLayers = tilemap.imageLayers
let groupLayers = tilemap.groupLayers

// query named layers
let groundLayers = tilemap.getLayers(named: "Ground") as! [SKTileLayer]
let objectGroups = tilemap.getLayers(named: "Objects") as! [SKObjectGroup]
let hudLayers = tilemap.getLayers(named: "HUD") as! [SKImageLayer]

// query layer at a specific index
if let firstLayer = tilemap.getLayer(atIndex: 1) as! SKTileLayer {
    firstLayer.visible = true
}

Working with Tiles

There are a number of ways to access and manipulate tile objects. Tiles can be queried from the SKTilemap node, or the parent SKTileLayer layer:

// access a tile via CGPoint
let tileCoord = CGPoint(x: 7, y: 12)
if let tile = groundLayer.tileAt(coord: tileCoord) {
    tile.tileData.tileOffset.x += 8
}

// access a tile with integer coordinates
if let tile = groundLayer.tileAt(7, 12) {
    tile.tileData.tileOffset.x += 8
}

// query tiles at a specific coordinate (all layers)
let tiles = tilemap.tilesAt(2, 4)

Tiles assigned custom properties in Tiled can be accessed in SKTiled:

// query tiles of a certain type
if let fireTiles = tilemap.getTiles(ofType: "fire") {
    // do something fiery here...
}

You can also return tiles with a specific ID value:

if let waterTiles = waterLayer.getTiles(globalID: 17) {
    // do something watery here...
}

Working with Objects

SKTileObject objects can be queried from both the SKTilemap and SKObjectGroup nodes:

let allObjects = tilemap.getObjects()
let allTreeObjects = tilemap.getObjects(named: "Tree")
let allCollisionObjects = tilemap.getObjects(ofType: "Collision")

// get objects from the objects group layer
let entrances = objectsLayer.getObjects(ofType: "Entrance")

Acessing Tile Data

The SKTilemap node stores an array of individual tilesets parsed from the original Tiled document. Individual tile data is accessible from either the SKTileset object:

let tileSet = tilemap.getTileset("spritesheet-16x16")
// get data for a specific id
let tileData = tileSet.getTileData(globalID: 177)

and the parent SKTilemap:

let tileData = tilemap.getTileData(globalID: 177)

Adding Nodes

Tile data includes texture data, and SKTile objects are SKSpriteNode subclasses that can be initialized with tileset data:

let newTile = SKTile(data: tileData)
scene.addChild(newTile)

Coordinate information is available from each layer via the SKTiledLayerObject.pointForCoordinate method:

let tilePoint = groundLayer.pointForCoordinate(4, 5)
tile.position = tilePoint

New nodes (any SKNode type) can be added directly to any layer. All SKTiledLayerObject layer types have expanded convenience methods for adding child nodes with coordinates and z-position.

let roadRoot = SKNode()
groundLayer.addChild(roadRoot, 4, 5, zpos: 100.0)

SKTiled also provides methods for getting coordinate data from UITouch and NSEvent mouse events:

// get the coordinate at the location of a touch event
let touchLocation: CGPoint = objectsLayer.coordinateAtTouchLocation(touch)

Animated Tiles

Tiles with animation will animate automatically when the tilemap node is added to the SKScene.update method. Animated tiles can be accesssed from the either the SKTilemap node or the parent layer.

// get all animated tiles, including nested layers
let allAnimated = tilemap.animatedTiles(recursive: true)

// pause/unpause tile animation
for tile in allAnimated {
    tile.isPaused = true
}

// run animation backwards
for tile in allAnimated {
    tile.speed = -1.0
}

// get animated tiles from individual layers
let layerAnimated = groundLayer.animatedTiles()

Custom Properties

Custom properties are supported on all object types. All SKTiled objects conform to the SKTiledObject protocol and allow access to and parsing of custom properties.

Any property added to an object in Tiled will be translated and stored in the SKTiledObject.properties dictionary.

let layerDepth = groundLayer.getValue(forProperty: "depth")
groundLayer.setValue(12.5, forProperty: "depth")

To query tiles of a given type:

let waterTiles = groundLayer.getTiles(ofType: "water")
let allWaterTiles = tilemap.getTiles(ofType: "water")

For specific property/value types:

let groundWalkable = groundLayer.getTilesWithProperty("walkable", true)
let allWalkable = tilemap.getTilesWithProperty("walkable", true")

Acknowledgments

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].