Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
- for touch in touches {
- let touchLocation = touch.location(in: self)
- player.position.x = touchLocation.x
- }
- }
- var isDragging = false
- var player = /* SKSpriteNode or whatever */
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- if let touch = touches.first {
- let touchLocation = touch.location(in: view)
- if player.contains(touchLocation) {
- isDragging = true
- }
- }
- }
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
- guard isDragging else { return }
- if let touch = touches.first {
- let touchLocation = touch.location(in: view)
- player.position.x = touchLocation.x
- }
- }
- override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
- isDragging = false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement