質問編集履歴

4

タイトルを修正

2015/10/12 09:19

投稿

K_S_
K_S_

スコア419

test CHANGED
@@ -1 +1 @@
1
- swift SpriteKit 線をドラッグ中にエラー
1
+ swift SKShapeNodeの頂点追加
test CHANGED
File without changes

3

語句の統一

2015/10/12 09:19

投稿

K_S_
K_S_

スコア419

test CHANGED
File without changes
test CHANGED
@@ -174,7 +174,7 @@
174
174
 
175
175
 
176
176
 
177
- Lineクラス
177
+ Lineクラス
178
178
 
179
179
  ```swift
180
180
 

2

コードの順番の変更

2015/10/12 07:31

投稿

K_S_
K_S_

スコア419

test CHANGED
File without changes
test CHANGED
@@ -22,12 +22,164 @@
22
22
 
23
23
 
24
24
 
25
-
25
+ GameSceneクラス
26
26
 
27
27
  ```swift
28
28
 
29
+
30
+
31
+
32
+
29
33
  import SpriteKit
30
34
 
35
+
36
+
37
+ class GameScene: SKScene {
38
+
39
+
40
+
41
+ var lines : [Line] = []
42
+
43
+ var currentLine : Line = Line()
44
+
45
+
46
+
47
+ override func didMoveToView(view: SKView) {
48
+
49
+ // sceneの背景を黒色に設定.
50
+
51
+ self.backgroundColor = UIColor.blackColor()
52
+
53
+ }
54
+
55
+
56
+
57
+ override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
58
+
59
+ for touch in touches {
60
+
61
+ if(!drawing)
62
+
63
+ {
64
+
65
+ touch_hash = touch.hash
66
+
67
+ genarateLine()
68
+
69
+ addLineVertex(touch.locationInNode(self))
70
+
71
+ // 以下のコードを有効にしてもエラーが出ない。
72
+
73
+ // for i in (1 ... 142){
74
+
75
+ // addLineVertex(touch.locationInNode(self))
76
+
77
+ // updateCurrentLine()
78
+
79
+ // }
80
+
81
+ drawing = true
82
+
83
+ }
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+
91
+ override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
92
+
93
+ for touch in touches {
94
+
95
+ let touchPos = touch.locationInNode(self)
96
+
97
+ if(drawing)
98
+
99
+ {
100
+
101
+ if(touch_hash == touch.hash)
102
+
103
+ {
104
+
105
+ // 約142回目でエラーが発生する
106
+
107
+ addLineVertex(touchPos)
108
+
109
+ updateCurrentLine()
110
+
111
+ }
112
+
113
+ }
114
+
115
+ }
116
+
117
+ }
118
+
119
+
120
+
121
+ override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
122
+
123
+ drawing = false
124
+
125
+ }
126
+
127
+
128
+
129
+ func updateCurrentLine(){
130
+
131
+ currentLine.DrawObject.removeFromParent()
132
+
133
+ // Pointの更新
134
+
135
+ currentLine.DrawObject = SKShapeNode(points: &(currentLine.Points), count: currentLine.Points.count)
136
+
137
+ self.addChild(currentLine.DrawObject)
138
+
139
+ }
140
+
141
+
142
+
143
+ func genarateLine()
144
+
145
+ {
146
+
147
+ currentLine = Line()
148
+
149
+ lines.append(currentLine)
150
+
151
+ self.addChild(currentLine.DrawObject)
152
+
153
+ }
154
+
155
+
156
+
157
+ func addLineVertex(touchPoint : CGPoint)
158
+
159
+ {
160
+
161
+ currentLine.AddVertex(touchPoint)
162
+
163
+ }
164
+
165
+
166
+
167
+ }
168
+
169
+
170
+
171
+
172
+
173
+ ```
174
+
175
+
176
+
177
+ Lineのクラス
178
+
179
+ ```swift
180
+
181
+ import SpriteKit
182
+
31
183
  import Foundation
32
184
 
33
185
  import UIKit
@@ -66,156 +218,6 @@
66
218
 
67
219
 
68
220
 
69
- ```swift
70
-
71
-
72
-
73
-
74
-
75
- import SpriteKit
76
-
77
-
78
-
79
- class GameScene: SKScene {
80
-
81
-
82
-
83
- var lines : [Line] = []
84
-
85
- var currentLine : Line = Line()
86
-
87
-
88
-
89
- override func didMoveToView(view: SKView) {
90
-
91
- // sceneの背景を黒色に設定.
92
-
93
- self.backgroundColor = UIColor.blackColor()
94
-
95
- }
96
-
97
-
98
-
99
- override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
100
-
101
- for touch in touches {
102
-
103
- if(!drawing)
104
-
105
- {
106
-
107
- touch_hash = touch.hash
108
-
109
- genarateLine()
110
-
111
- addLineVertex(touch.locationInNode(self))
112
-
113
- // 以下のコードを有効にしてもエラーが出ない。
114
-
115
- // for i in (1 ... 142){
116
-
117
- // addLineVertex(touch.locationInNode(self))
118
-
119
- // updateCurrentLine()
120
-
121
- // }
122
-
123
- drawing = true
124
-
125
- }
126
-
127
- }
128
-
129
- }
130
-
131
-
132
-
133
- override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
134
-
135
- for touch in touches {
136
-
137
- let touchPos = touch.locationInNode(self)
138
-
139
- if(drawing)
140
-
141
- {
142
-
143
- if(touch_hash == touch.hash)
144
-
145
- {
146
-
147
- // 約142回目でエラーが発生する
148
-
149
- addLineVertex(touchPos)
150
-
151
- updateCurrentLine()
152
-
153
- }
154
-
155
- }
156
-
157
- }
158
-
159
- }
160
-
161
-
162
-
163
- override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
164
-
165
- drawing = false
166
-
167
- }
168
-
169
-
170
-
171
- func updateCurrentLine(){
172
-
173
- currentLine.DrawObject.removeFromParent()
174
-
175
- // Pointの更新
176
-
177
- currentLine.DrawObject = SKShapeNode(points: &(currentLine.Points), count: currentLine.Points.count)
178
-
179
- self.addChild(currentLine.DrawObject)
180
-
181
- }
182
-
183
-
184
-
185
- func genarateLine()
186
-
187
- {
188
-
189
- currentLine = Line()
190
-
191
- lines.append(currentLine)
192
-
193
- self.addChild(currentLine.DrawObject)
194
-
195
- }
196
-
197
-
198
-
199
- func addLineVertex(touchPoint : CGPoint)
200
-
201
- {
202
-
203
- currentLine.AddVertex(touchPoint)
204
-
205
- }
206
-
207
-
208
-
209
- }
210
-
211
-
212
-
213
-
214
-
215
- ```
216
-
217
-
218
-
219
221
  ```
220
222
 
221
223
  エラー文

1

コードの一部の追加

2015/10/12 07:30

投稿

K_S_
K_S_

スコア419

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,14 @@
26
26
 
27
27
  ```swift
28
28
 
29
+ import SpriteKit
30
+
31
+ import Foundation
32
+
33
+ import UIKit
34
+
35
+
36
+
29
37
  class Line{
30
38
 
31
39
  var Points : [CGPoint] = []