Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. // Space out the graphics.
  2. let placeDistance = touch.position.distance(from: lastPlacePosition)
  3. if placeDistance < /*#-editable-code*/80/*#-end-editable-code*/ { return }
  4. lastPlacePosition = touch.position
  5.  
  6. // animals数列から動物をランダムにピックアップ
  7. let chosenImage = animals.randomItem
  8.  
  9. // ピックアップした動物をgraphics数列に3つ入れる
  10. for i in 0 ..< 4 {
  11. let graphic = Graphic(image: chosenImage)
  12. graphics.append(graphic)
  13. }
  14.  
  15. // 画面をタッチした絶対座標を求める
  16. let x = abs(touch.position.x)
  17. let y = abs(touch.position.y)
  18.  
  19. // 右上・右下・左上・左下の座標を決める
  20. let position1 = Point(x: x, y: y)
  21. let position2 = Point(x: -x, y: y)
  22. let position3 = Point(x: x, y: -y)
  23. let position4 = Point(x: -x, y: -y)
  24.  
  25. //このforループの意味がわからない
  26. for i in 0 ..< 4 {
  27. if i == 0 {
  28. scene.place(graphics[i], at: position1)
  29. } else if i == 1 {
  30. scene.place(graphics[i], at: position2)
  31. } else if i == 2 {
  32. scene.place(graphics[i], at: position3)
  33. } else if i == 3 {
  34. scene.place(graphics[i], at: position4)
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement