-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathViewController.swift
90 lines (71 loc) · 2.83 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// ViewController.swift
// ExampleController
//
// Created by Umberto Sonnino on 11/21/19.
// Copyright © 2019 2Dimensions. All rights reserved.
//
import UIKit
/// To use on a physical device.
//import FlareSwift
/// To use on a Simulator.
import FlareSwiftDev
class ViewController: UIViewController {
private var button: UIButton!
private var flareController: CustomController? = nil
private var soloNode: ActorNodeSolo? = nil
private var artboard: ActorArtboard? = nil
var count: Int = 1
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.darkGray
let screenFrame = UIScreen.main.bounds
let x = CGFloat(50)
let y = CGFloat(200)
flareController = CustomController(
for: "Cactus.flr",
CGRect(x: x, y: y, width: screenFrame.width - (x*2), height: screenFrame.height - (y*2))
)
flareController!.animationName = "Idle"
addChild(flareController!)
if let fView = flareController!.view as? FlareSkView {
view.addSubview(fView)
fView.translatesAutoresizingMaskIntoConstraints = false
flareController!.didMove(toParent: self)
// Assign the artboard reference.
artboard = fView.artboard
// Assign the Node Solo reference.
soloNode = artboard?.getNode(name: "Mustache_Solo") as? ActorNodeSolo
/** UNCOMMENT TO TEST
let myNode = artboard?.getNode(name: "Face")
print(myNode?.x)
print(myNode?.y)
print(myNode?.scaleX)
print(myNode?.scaleY)
print(myNode?.rotation)
print(myNode?.opacity)
print(artboard?.getNode(name: "Scale Node_Special Property")?.name)
let boneNode = artboard?.getNode(name: "Bone") as? ActorBoneBase
print(boneNode?.length as Any)
*/
let buttonWidth = screenFrame.width/2
button = UIButton(frame: CGRect(x: buttonWidth/2, y: 50, width: buttonWidth, height: 100))
button.backgroundColor = UIColor.systemIndigo
button.setTitleColor(.white, for: .normal)
button.setTitle("Change Mustache", for: .normal)
button.addTarget(self, action: #selector(onTap), for: .touchUpInside)
view.addSubview(button)
} else {
/* Something went wrong? */
print("Couldn't get FlareController subview?")
}
}
@objc func onTap() {
self.flareController!.play(name: "Mustache_New")//, mix: 0.5, mixSeconds: 1.0
count += 1
if(count > 5){
count = 1;
}
soloNode?.setActiveChildIndex(count)
}
}