Instantly share code, notes, and snippets.

@natmark /PitagoraView.swift Secret
Last active Dec 12, 2017

Embed
What would you like to do?
//
// PitagoraView.swift
// ipad-pitagora
//
// Created by AtsuyaSato on 2017/12/12.
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//
import ProcessingKit
import simple_tween
// シーンをenumで定義
public enum Scene: Int, Countable {
case scene1
case scene2
case scene3
case scene4
}
class PitagoraView: ProcessingView {
var sceneInfos = [(tween: Tween, setup: Selector?, draw: Selector?)]() //シーンにおける情報を保持
func setup() {
sceneInfos = Array(repeating: (Tween(0), nil, nil), count: Scene.count) //初期化
setupScene1()
setupScene2()
setupScene3()
setupScene4()
startScene(scene: .scene1)
}
func draw() {
for (index, element) in sceneInfos.enumerated() {
if element.tween.isTweening {
perform(element.draw)
} else if element.tween.position == 1.0 && index < Scene.count - 1 {
startScene(scene: Scene(rawValue: index + 1)!)
}
}
}
func startScene(scene: Scene) { // シーンを指定して、再生を行う
if sceneInfos[scene.rawValue].tween.position == 0.0 {
sceneInfos[scene.rawValue].tween.start()
perform(sceneInfos[scene.rawValue].setup)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment