回答編集履歴

2

コード修正・追加回答のサンプルコードの変数名の修正

2016/10/08 16:10

投稿

renas
renas

スコア28

test CHANGED
@@ -108,11 +108,11 @@
108
108
 
109
109
  for i in 0 ..< nodes.count {
110
110
 
111
- if arrayNode[i].name != nil {
111
+ if nodes[i].name != nil {
112
112
 
113
- print(arrayNode[i].name)
113
+ print[nodes[i].name)
114
114
 
115
- print(arrayNode[i].position)
115
+ print(nodes[i].position)
116
116
 
117
117
  }
118
118
 

1

質問の意図に対し回答不十分により補足・追加しました

2016/10/08 16:10

投稿

renas
renas

スコア28

test CHANGED
@@ -65,3 +65,69 @@
65
65
 
66
66
 
67
67
  設定や登録といった作業が必要になるのはUITapGestureRecognizerのことかも知れません。
68
+
69
+
70
+
71
+ ---
72
+
73
+
74
+
75
+ 回答追加1
76
+
77
+
78
+
79
+ 画面上のタッチ数とタッチ押下のスプライトを列挙するコードです。
80
+
81
+ ```swift
82
+
83
+ override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
84
+
85
+
86
+
87
+ var nodes:[SKNode]!
88
+
89
+ print(touches.count)
90
+
91
+
92
+
93
+ //タッチカ所分繰り返す
94
+
95
+ for touch: AnyObject in touches {
96
+
97
+
98
+
99
+ let touchLocation = touch.locationInNode(self)
100
+
101
+
102
+
103
+ //タッチしたポイントにあるノードを返す
104
+
105
+ nodes=self.nodesAtPoint(touch.locationInNode(self))
106
+
107
+ //ノード数分繰り返す
108
+
109
+ for i in 0 ..< nodes.count {
110
+
111
+ if arrayNode[i].name != nil {
112
+
113
+ print(arrayNode[i].name)
114
+
115
+ print(arrayNode[i].position)
116
+
117
+ }
118
+
119
+ }
120
+
121
+ }
122
+
123
+ ```
124
+
125
+
126
+
127
+ タッチ後にタッチ座標のスプライトの有無を調べています。名前と座標を表示します。
128
+
129
+ 手がかりになれば幸いです。
130
+
131
+ タッチ座標に追従した形にする場合、非表示のスプライトを用意してphysicsBodyで呼ぶなどどうでしょう。
132
+
133
+