SpriteKit を用いて タモさん を神と崇める feat. Playground


はじめに

  • 前回の続きです

SpriteKit を用いて 田代まさしを左右に動かす feat. Playground

アニメ

  • Preview.app で適当に作成した画像をループする

コード

タモさん.swift
//: Playground - noun: a place where people can play

import SpriteKit
import XCPlayground

struct Constants {
    static let TamoriImages = ["tamori", "tamori1", "tamori2", "tamori3"]
}

let sceneWidth = 500
let sceneHeight = 500

internal var tamori: SKSpriteNode!

func repeatTamosan(scene: SKScene) -> Void {
    var playerTexture = [SKTexture]()

    for imageName in Constants.TamoriImages {
        let texture = SKTexture(imageNamed: imageName)
        texture.filteringMode = .Linear
        playerTexture.append(texture)
    }
    let playerAnimation = SKAction.animateWithTextures(playerTexture, timePerFrame: 0.2)
    let loopAnimation = SKAction.repeatAction(playerAnimation, count: 10)

    tamori = SKSpriteNode(texture: playerTexture[0])
    tamori.position = CGPoint(x: 250, y: 250)
    tamori.runAction(loopAnimation)

    scene.addChild(tamori)
}

let skView = SKView(frame: CGRect(x: 0, y: 0, width: sceneWidth, height: sceneWidth))
let skScene = SKScene(size: CGSize(width: sceneWidth, height: sceneHeight))

repeatTamosan(skScene)
skView.presentScene(skScene)
XCPShowView("Live SKView: Iitomo", view: skView)

Playground

  • 今回は無しで...

Reference