質問編集履歴
1
要点になっていそうなコードを載せました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,82 @@
|
|
9
9
|
###発生している問題
|
10
10
|
リトライボタンを押した際、画面はゲーム開始時の状態に戻りますが、UIGestureRecognizerが反応しなくなり、ドラッグアンドドロップができない状態になります。
|
11
11
|
|
12
|
-
遷移後もドラッグアンドドロップできる状態にするにはどうしたらよいのでしょうか。
|
12
|
+
遷移後もドラッグアンドドロップできる状態にするにはどうしたらよいのでしょうか。
|
13
|
+
|
14
|
+
|
15
|
+
GameViewController
|
16
|
+
```
|
17
|
+
var panPointReference: CGPoint?
|
18
|
+
@IBAction func didPan(_ sender: UIPanGestureRecognizer) {
|
19
|
+
if scene.status == "wait"{
|
20
|
+
scene.timerStart()
|
21
|
+
}
|
22
|
+
if scene.timeLimit == 0 {
|
23
|
+
return
|
24
|
+
}
|
25
|
+
let currentPoint = sender.translation(in: self.view)
|
26
|
+
if panPointReference != nil {
|
27
|
+
// print("currentPoint: \(currentPoint)")
|
28
|
+
scene.moving(p:currentPoint)
|
29
|
+
} else if sender.state == .began {
|
30
|
+
// print(".Began")
|
31
|
+
panPointReference = currentPoint
|
32
|
+
}
|
33
|
+
if sender.state == .ended {
|
34
|
+
// print(".Ended")
|
35
|
+
panPointReference = nil
|
36
|
+
scene.movingEnd(vector: scene.vector)
|
37
|
+
scene.vector = ""
|
38
|
+
}
|
39
|
+
}
|
40
|
+
```
|
41
|
+
GameScene
|
42
|
+
```
|
43
|
+
func timeUp(){
|
44
|
+
status = "timeUp"
|
45
|
+
timer.invalidate()
|
46
|
+
let retryButton = Button(text: "retry?",
|
47
|
+
rect: CGRect(x:200,y:40,width:100,height:30),
|
48
|
+
afterTap:{[weak self] in
|
49
|
+
let scene = GameScene(size: (self?.scene!.size)!)
|
50
|
+
scene.status = "wait"
|
51
|
+
self?.isPaused = false
|
52
|
+
scene.scaleMode = .resizeFill
|
53
|
+
self?.view?.presentScene(scene)
|
54
|
+
})
|
55
|
+
addChild(retryButton)
|
56
|
+
}
|
57
|
+
```
|
58
|
+
ButtonClass
|
59
|
+
```
|
60
|
+
class Button: SKSpriteNode {
|
61
|
+
let afterTap:() ->()
|
62
|
+
|
63
|
+
init (text: String,rect: CGRect, afterTap: @escaping () -> ()) {
|
64
|
+
self.afterTap = afterTap
|
65
|
+
super.init(texture: nil, color: UIColor.clear, size: rect.size)
|
66
|
+
position = rect.origin
|
67
|
+
isUserInteractionEnabled = true
|
68
|
+
|
69
|
+
let rectplus = SKShapeNode(rect: CGRect(origin: CGPoint(), size:rect.size),cornerRadius:4.0)
|
70
|
+
rectplus.fillColor = UIColor.clear
|
71
|
+
rectplus.strokeColor = UIColor.clear
|
72
|
+
addChild(rectplus)
|
73
|
+
|
74
|
+
let pluslabel = SKLabelNode(fontNamed: "MarkerFelt-Thin")
|
75
|
+
pluslabel.text = text
|
76
|
+
pluslabel.fontSize = CGFloat(30)
|
77
|
+
pluslabel.fontColor = UIColor.black
|
78
|
+
pluslabel.position = CGPoint(x:rect.width / 2, y: rect.height / 2 - pluslabel.frame.height / 2)
|
79
|
+
pluslabel.zPosition = 7
|
80
|
+
addChild(pluslabel)
|
81
|
+
}
|
82
|
+
|
83
|
+
required init?(coder aDecoder: NSCoder) {
|
84
|
+
fatalError("init(coder:) has not been implemented")
|
85
|
+
}
|
86
|
+
override func touchesEnded(_ touches:Set<UITouch>,with event:UIEvent?){
|
87
|
+
afterTap()
|
88
|
+
}
|
89
|
+
}
|
90
|
+
```
|