質問編集履歴
1
要点になっていそうなコードを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,3 +21,159 @@
|
|
21
21
|
|
22
22
|
|
23
23
|
遷移後もドラッグアンドドロップできる状態にするにはどうしたらよいのでしょうか。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
GameViewController
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
var panPointReference: CGPoint?
|
34
|
+
|
35
|
+
@IBAction func didPan(_ sender: UIPanGestureRecognizer) {
|
36
|
+
|
37
|
+
if scene.status == "wait"{
|
38
|
+
|
39
|
+
scene.timerStart()
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
if scene.timeLimit == 0 {
|
44
|
+
|
45
|
+
return
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
let currentPoint = sender.translation(in: self.view)
|
50
|
+
|
51
|
+
if panPointReference != nil {
|
52
|
+
|
53
|
+
// print("currentPoint: \(currentPoint)")
|
54
|
+
|
55
|
+
scene.moving(p:currentPoint)
|
56
|
+
|
57
|
+
} else if sender.state == .began {
|
58
|
+
|
59
|
+
// print(".Began")
|
60
|
+
|
61
|
+
panPointReference = currentPoint
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
if sender.state == .ended {
|
66
|
+
|
67
|
+
// print(".Ended")
|
68
|
+
|
69
|
+
panPointReference = nil
|
70
|
+
|
71
|
+
scene.movingEnd(vector: scene.vector)
|
72
|
+
|
73
|
+
scene.vector = ""
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
GameScene
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
func timeUp(){
|
86
|
+
|
87
|
+
status = "timeUp"
|
88
|
+
|
89
|
+
timer.invalidate()
|
90
|
+
|
91
|
+
let retryButton = Button(text: "retry?",
|
92
|
+
|
93
|
+
rect: CGRect(x:200,y:40,width:100,height:30),
|
94
|
+
|
95
|
+
afterTap:{[weak self] in
|
96
|
+
|
97
|
+
let scene = GameScene(size: (self?.scene!.size)!)
|
98
|
+
|
99
|
+
scene.status = "wait"
|
100
|
+
|
101
|
+
self?.isPaused = false
|
102
|
+
|
103
|
+
scene.scaleMode = .resizeFill
|
104
|
+
|
105
|
+
self?.view?.presentScene(scene)
|
106
|
+
|
107
|
+
})
|
108
|
+
|
109
|
+
addChild(retryButton)
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
ButtonClass
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
class Button: SKSpriteNode {
|
120
|
+
|
121
|
+
let afterTap:() ->()
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
init (text: String,rect: CGRect, afterTap: @escaping () -> ()) {
|
126
|
+
|
127
|
+
self.afterTap = afterTap
|
128
|
+
|
129
|
+
super.init(texture: nil, color: UIColor.clear, size: rect.size)
|
130
|
+
|
131
|
+
position = rect.origin
|
132
|
+
|
133
|
+
isUserInteractionEnabled = true
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
let rectplus = SKShapeNode(rect: CGRect(origin: CGPoint(), size:rect.size),cornerRadius:4.0)
|
138
|
+
|
139
|
+
rectplus.fillColor = UIColor.clear
|
140
|
+
|
141
|
+
rectplus.strokeColor = UIColor.clear
|
142
|
+
|
143
|
+
addChild(rectplus)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
let pluslabel = SKLabelNode(fontNamed: "MarkerFelt-Thin")
|
148
|
+
|
149
|
+
pluslabel.text = text
|
150
|
+
|
151
|
+
pluslabel.fontSize = CGFloat(30)
|
152
|
+
|
153
|
+
pluslabel.fontColor = UIColor.black
|
154
|
+
|
155
|
+
pluslabel.position = CGPoint(x:rect.width / 2, y: rect.height / 2 - pluslabel.frame.height / 2)
|
156
|
+
|
157
|
+
pluslabel.zPosition = 7
|
158
|
+
|
159
|
+
addChild(pluslabel)
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
required init?(coder aDecoder: NSCoder) {
|
166
|
+
|
167
|
+
fatalError("init(coder:) has not been implemented")
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
override func touchesEnded(_ touches:Set<UITouch>,with event:UIEvent?){
|
172
|
+
|
173
|
+
afterTap()
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|