回答編集履歴
3
Codeを見やすくしました
test
CHANGED
@@ -18,11 +18,11 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
let sHand = SKSpriteNode(color:
|
21
|
+
let sHand = SKSpriteNode(color: UIColor.red, size: CGSize(width: 2, height: 180))
|
22
|
-
|
22
|
+
|
23
|
-
let mHand = SKSpriteNode(color:
|
23
|
+
let mHand = SKSpriteNode(color: UIColor.black, size: CGSize(width: 5, height: 180))
|
24
|
-
|
24
|
+
|
25
|
-
let hHand = SKSpriteNode(color:
|
25
|
+
let hHand = SKSpriteNode(color: UIColor.black, size: CGSize(width: 5, height: 140))
|
26
26
|
|
27
27
|
|
28
28
|
|
@@ -98,7 +98,7 @@
|
|
98
98
|
|
99
99
|
// ShapeNodeの塗りつぶしの色を指定.
|
100
100
|
|
101
|
-
Circle.fillColor =
|
101
|
+
Circle.fillColor = UIColor.white
|
102
102
|
|
103
103
|
Circle.zPosition = CGFloat(-2.0)
|
104
104
|
|
@@ -114,7 +114,7 @@
|
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
-
let memori=SKSpriteNode(color:
|
117
|
+
let memori=SKSpriteNode(color: UIColor.gray, size: CGSize(width: 1, height: 14))
|
118
118
|
|
119
119
|
// ShapeNodeの座標を指定.
|
120
120
|
|
@@ -144,7 +144,7 @@
|
|
144
144
|
|
145
145
|
|
146
146
|
|
147
|
-
let memori = SKSpriteNode(color:
|
147
|
+
let memori = SKSpriteNode(color: UIColor.black, size: CGSize(width: 5, height: 14))
|
148
148
|
|
149
149
|
// ShapeNodeの座標を指定.
|
150
150
|
|
2
コードを見やすくしました
test
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
func DegreeToRadian(Degree:Double)->CGFloat{
|
49
|
+
func DegreeToRadian(Degree:Double) -> CGFloat {
|
50
50
|
|
51
51
|
return CGFloat(Degree) / CGFloat(180.0 * M_1_PI)
|
52
52
|
|
@@ -72,10 +72,222 @@
|
|
72
72
|
|
73
73
|
//取得するコンポーネントを決める.
|
74
74
|
|
75
|
+
myComponetns = myCalendar.components([.hour, .minute, .second], from: myDate as Date) as NSDateComponents!
|
76
|
+
|
77
|
+
sec = Double(myComponetns.second * -6 )
|
78
|
+
|
79
|
+
min = Double(myComponetns.minute * -6)
|
80
|
+
|
81
|
+
hour = Double((myComponetns.hour-12) * -30)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//盤面
|
86
|
+
|
87
|
+
// ShapeNodeを作成.
|
88
|
+
|
89
|
+
let Circle = SKShapeNode(circleOfRadius: 190)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// ShapeNodeの座標を指定.
|
94
|
+
|
95
|
+
Circle.position = CGPoint(x: frame.midX, y: frame.midY)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
// ShapeNodeの塗りつぶしの色を指定.
|
100
|
+
|
101
|
+
Circle.fillColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
|
102
|
+
|
103
|
+
Circle.zPosition = CGFloat(-2.0)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
// sceneにShapeNodeを追加.
|
108
|
+
|
109
|
+
self.addChild(Circle)
|
110
|
+
|
111
|
+
//var cArr: [SKShapeNode] = []
|
112
|
+
|
113
|
+
for i in 1...60 {
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
let memori=SKSpriteNode(color: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), size: CGSize(width: 1, height: 14))
|
118
|
+
|
119
|
+
// ShapeNodeの座標を指定.
|
120
|
+
|
121
|
+
memori.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
memori.zPosition = CGFloat(2.0)
|
126
|
+
|
127
|
+
memori.anchorPoint = CGPoint(x: 0.5, y: -12)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
memori.zRotation = DegreeToRadian(Degree: Double(-6 * i))
|
132
|
+
|
133
|
+
//cArr.append(Circle2)
|
134
|
+
|
135
|
+
addChild(memori)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
for i in 1...12 {
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
let memori = SKSpriteNode(color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), size: CGSize(width: 5, height: 14))
|
148
|
+
|
149
|
+
// ShapeNodeの座標を指定.
|
150
|
+
|
151
|
+
memori.position = CGPoint(x: frame.midX, y: frame.midY)
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
memori.zPosition = CGFloat(2.0)
|
158
|
+
|
159
|
+
memori.anchorPoint = CGPoint(x: 0.5, y: -12)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
memori.zRotation = DegreeToRadian(Degree: Double(-30 * i))
|
164
|
+
|
165
|
+
//cArr.append(Circle2)
|
166
|
+
|
167
|
+
addChild(memori)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
//四角形の描画
|
176
|
+
|
177
|
+
//秒
|
178
|
+
|
179
|
+
sHand.position = CGPoint(x: frame.midX, y: frame.midY)
|
180
|
+
|
181
|
+
sHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
182
|
+
|
183
|
+
sHand.zRotation = DegreeToRadian(Degree: sec)
|
184
|
+
|
185
|
+
addChild(sHand)
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//分
|
190
|
+
|
191
|
+
mHand.position = CGPoint(x: frame.midX, y: frame.midY)
|
192
|
+
|
193
|
+
mHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
194
|
+
|
195
|
+
mHand.zRotation = DegreeToRadian(Degree: min+(6*(sec/360)))
|
196
|
+
|
197
|
+
print(min + (6 * (sec / 360)))
|
198
|
+
|
199
|
+
addChild(mHand)
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
//時
|
204
|
+
|
205
|
+
hHand.position = CGPoint(x: frame.midX, y: frame.midY)
|
206
|
+
|
207
|
+
hHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
208
|
+
|
209
|
+
hHand.zRotation = DegreeToRadian(Degree: hour + (30 * (min / 360)))
|
210
|
+
|
211
|
+
print(hour)
|
212
|
+
|
213
|
+
addChild(hHand)
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
func touchDown(atPoint pos : CGPoint) {
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
func touchMoved(toPoint pos : CGPoint) {
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
func touchUp(atPoint pos : CGPoint) {
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
override func update(_ currentTime: TimeInterval) {
|
280
|
+
|
281
|
+
// Called before each frame is rendered
|
282
|
+
|
283
|
+
myDate = NSDate()
|
284
|
+
|
75
285
|
myComponetns = myCalendar.components(
|
76
286
|
|
77
287
|
[.hour, .minute, .second], from: myDate as Date) as NSDateComponents!
|
78
288
|
|
289
|
+
|
290
|
+
|
79
291
|
sec = Double(myComponetns.second * -6 )
|
80
292
|
|
81
293
|
min = Double(myComponetns.minute * -6)
|
@@ -84,224 +296,12 @@
|
|
84
296
|
|
85
297
|
|
86
298
|
|
87
|
-
//盤面
|
88
|
-
|
89
|
-
// ShapeNodeを作成.
|
90
|
-
|
91
|
-
let Circle = SKShapeNode(circleOfRadius: 190)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
// ShapeNodeの座標を指定.
|
96
|
-
|
97
|
-
Circle.position = CGPoint(x: self.frame.midX, y:self.frame.midY)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
// ShapeNodeの塗りつぶしの色を指定.
|
102
|
-
|
103
|
-
Circle.fillColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
|
104
|
-
|
105
|
-
Circle.zPosition = CGFloat(-2.0)
|
106
|
-
|
107
|
-
// sceneにShapeNodeを追加.
|
108
|
-
|
109
|
-
self.addChild(Circle)
|
110
|
-
|
111
|
-
var cArr: [SKShapeNode] = []
|
112
|
-
|
113
|
-
for i in 1...60 {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
let memori=SKSpriteNode(color: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), size: CGSize(width: 1, height: 14))
|
118
|
-
|
119
|
-
// ShapeNodeの座標を指定.
|
120
|
-
|
121
|
-
memori.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
memori.zPosition = CGFloat(2.0)
|
126
|
-
|
127
|
-
memori.anchorPoint = CGPoint(x: 0.5, y: -12)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
memori.zRotation = DegreeToRadian(Degree: Double(-6 * i))
|
132
|
-
|
133
|
-
cArr.append(Circle)
|
134
|
-
|
135
|
-
self.addChild(memori)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
for i in 1...12 {
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
let memori = SKSpriteNode(color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), size: CGSize(width: 5, height: 14))
|
148
|
-
|
149
|
-
// ShapeNodeの座標を指定.
|
150
|
-
|
151
|
-
memori.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
memori.zPosition = CGFloat(2.0)
|
158
|
-
|
159
|
-
memori.anchorPoint = CGPoint(x: 0.5, y: -12)
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
memori.zRotation = DegreeToRadian(Degree: Double(-30 * i))
|
164
|
-
|
165
|
-
cArr.append(Circle)
|
166
|
-
|
167
|
-
self.addChild(memori)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
//四角形の描画
|
176
|
-
|
177
|
-
//秒
|
178
|
-
|
179
|
-
sHand.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
180
|
-
|
181
|
-
sHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
182
|
-
|
183
299
|
sHand.zRotation = DegreeToRadian(Degree: sec)
|
184
300
|
|
185
|
-
self.addChild(sHand)
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
//分
|
190
|
-
|
191
|
-
mHand.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
192
|
-
|
193
|
-
mHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
194
|
-
|
195
|
-
mHand.zRotation = DegreeToRadian(Degree: min+(6*(sec/360)))
|
301
|
+
mHand.zRotation = DegreeToRadian(Degree: min + (6 * (sec / 360)))
|
196
|
-
|
197
|
-
print(min + (6 * (sec / 360)))
|
198
|
-
|
199
|
-
self.addChild(mHand)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//時
|
204
|
-
|
205
|
-
hHand.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
|
206
|
-
|
207
|
-
hHand.anchorPoint = CGPoint(x: 0.5, y: 0)
|
208
302
|
|
209
303
|
hHand.zRotation = DegreeToRadian(Degree: hour + (30 * (min / 360)))
|
210
304
|
|
211
|
-
print(hour)
|
212
|
-
|
213
|
-
self.addChild(hHand)
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
func touchDown(atPoint pos : CGPoint) {
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
func touchMoved(toPoint pos : CGPoint) {
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
func touchUp(atPoint pos : CGPoint) {
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
override func update(_ currentTime: TimeInterval) {
|
280
|
-
|
281
|
-
// Called before each frame is rendered
|
282
|
-
|
283
|
-
myDate = NSDate()
|
284
|
-
|
285
|
-
myComponetns = myCalendar.components(
|
286
|
-
|
287
|
-
[.hour, .minute, .second], from: myDate as Date) as NSDateComponents!
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
sec = Double(myComponetns.second * -6 )
|
292
|
-
|
293
|
-
min = Double(myComponetns.minute * -6)
|
294
|
-
|
295
|
-
hour = Double((myComponetns.hour-12) * -30)
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
sHand.zRotation = DegreeToRadian(Degree: sec)
|
300
|
-
|
301
|
-
mHand.zRotation = DegreeToRadian(Degree: min + (6 * (sec / 360)))
|
302
|
-
|
303
|
-
hHand.zRotation = DegreeToRadian(Degree: hour + (30 * (min / 360)))
|
304
|
-
|
305
305
|
}
|
306
306
|
|
307
307
|
}
|
1
誤字を修正しました
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
解決していたら無視してください
|
2
2
|
|
3
|
-
Xcode Version 8.2.1、Simulator Version 10.0を使用している場合で
|
3
|
+
Xcode Version 8.2.1、Simulator Version 10.0を使用している場合で解説いたします、Xcodeで File → New → projectでGameを選択してお好みのProduct NameでLanguageはswift、Game TechnologyはSpriteKitを選択して作成します、作成されたGameScene.swiftを書き換えてください、これで私の環境ではSimulatorで時計とHello Worldが表示します
|
4
4
|
|
5
5
|
また、ご存知と思いますがGameScene.swiftのclass GameScene名をGameSecne1とかに変更したらGameScene.sksのCustom Class名も同様にGameSecne1に変更すれば時計は表示します、また、GameScene.sksのScene Colarを変更すれば背景色が変化します、参考になれば幸いです
|
6
6
|
|