Latest 1.2.1
Homepage https://github.com/maxgribov/Spine
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0, watchos 3.0
Frameworks SpriteKit
Authors

Build Status
Pod Version

This Swift library allows you to upload characters and their animations from the Spine app to SpriteKit for platforms:

iOS macOS tvOS watchOS

Implemented almost all the functionality of the essential version of Spine app:
Animation of bones, skins, animation of slots, creation of physical bodies on the basis of bounding boxes and some other. See Implemented Features for more information.

Hero

Installing

CocoaPods

Add the pod to your podfile

pod 'Spine'

run

pod install

Basic Usage

Assets

Files

  1. In assets catalog create folder. (Goblins folder in example below)
  2. Create sprite atlases. (default, goblin and goblingirl sprite atlases in example below)
  3. Put images into sprite atlaces.

    Note that the images that are in the root folder of the Spine app project must be in the sprite atlas named default in the Xcode project.

Final result should looks something like this:

Assets

Namespace

Set Provides Namespace option enabled for the root folder and for all sprite atlases in the Xcode’s attribute inspector:

Namespace

If you forget to set the namespace, later when you initialize your character images can be just not found.

JSON

Put the JSON exported from the Spine application somewhere in your project:

json

For more information about assets see Assets Wiki

Code

Somewhere at the beginning of your code, import the Spine library:

import Spine

The easiest way to load a character from a JSON file and apply skin to it is to use the appropriate Skeleton class constructor:

if let character = Skeleton(fromJSON: "goblins-ess", atlas: "Goblins", skin: "goblin") {

   //Do something with your character here
}

Skeleton is a subclass of SKNode, so you can do with it whatever you can do with SKNode itself

This way you can apply the animation created in Spine to the character:

if let walkAnimation = character.animation(named: "walk") {

    character.run(walkAnimation)
}

The animation(named:) method returns an object of the SKAction class so that you can use this animation as any other object of the SKAction class

This is an example of the simplest scene in which we load our Goblin character, add it to the scene and start walk animation in an endless loop:

import SpriteKit
import Spine

class GameScene: SKScene {

    override func didMove(to view: SKView) {

        if let character = Skeleton(fromJSON: "goblins-ess", atlas: "Goblins", skin: "goblin"){

            character.name = "goblin"
            character.position = CGPoint(x: self.size.width / 2, y: (self.size.height / 2))

            self.addChild(character)

            if let walkAnimation = character.animation(named: "walk") {

                character.run(SKAction.repeatForever(walkAnimation))
            }
        }
    }
}

Implemented Features

Name Model Feature Animation
Bones
– Rotation + + +
– Translation + + +
– Scale + + +
– Shear +
Bones extras:
– Reflect +
– Rotation Inheritance +
– Scale Inheritance +
– Reflect Inheritance +
Slots
– Attachment + + +
– Tint Color + + +/-
– Dark Tint Color +
Skins + +
Attachments
– Region + +
– Mesh +
– Linked Mesh +
– Bounding Box + +
– Path +
– Point + +
– Clipping +
Constraints
– IK Constraint +
– Transform Constraint +
– Path Constraint +
Events + + +
Draw Order + + +

System Requirements

Swift 4.1

  • iOS 8.0+
  • macOS 10.10+
  • tvOS 9.0+
  • watchOS 3.0+

License

This project is licensed under the MIT License – see the LICENSE file for details

Useful links

Latest podspec

{
    "name": "Spine",
    "version": "1.2.1",
    "summary": "Unofficial Spine runtime library for iOS, macOS, tvOS and watchOS",
    "description": "This library allows you to play animations created with the Spine App: http://esotericsoftware.comnAnimations are played using the graphics engine SpriteKit.nnSystem requirements:n====================niOS 8.0+nmacOS 10.10+ntvOS 9.0+nwatchOS 3.0+nnSwift 4.0+nnSee the source at https://github.com/maxgribov/Spine",
    "homepage": "https://github.com/maxgribov/Spine",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Max Gribov": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "3.0"
    },
    "source": {
        "git": "https://github.com/maxgribov/Spine.git",
        "tag": "v1.2.1"
    },
    "source_files": "Spine/**/*.swift",
    "frameworks": "SpriteKit"
}

Pin It on Pinterest

Share This