-
-
Save natmark/e908d3586617a16398423d2de15c0cb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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