Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  2. for touch in touches {
  3. let touchLocation = touch.location(in: self)
  4. player.position.x = touchLocation.x
  5.  
  6. }
  7. }
  8.  
  9. var isDragging = false
  10. var player = /* SKSpriteNode or whatever */
  11.  
  12.  
  13. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  14. if let touch = touches.first {
  15. let touchLocation = touch.location(in: view)
  16. if player.contains(touchLocation) {
  17. isDragging = true
  18. }
  19. }
  20. }
  21.  
  22. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  23. guard isDragging else { return }
  24.  
  25. if let touch = touches.first {
  26. let touchLocation = touch.location(in: view)
  27. player.position.x = touchLocation.x
  28. }
  29. }
  30.  
  31. override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
  32. isDragging = false
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement