Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
- let pos = touches.first!.location(in: view)
- let center = view!.center
- let xDist = pos.x - center.x
- let yDist = pos.y - center.y
- let distance = sqrt((xDist * xDist) + (yDist * yDist)) * 0.02
- camera?.position.x += xDist * distance * 0.02
- camera?.position.y -= yDist * distance * 0.02
- }
- private var difference = CGVector()
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
- let pos = touches.first!.location(in: view)
- let center = view!.center
- difference = CGVector(dx: pos.x - center.x, dy: pos.y - center.y)
- }
- override func update(_ currentTime: TimeInterval) {
- let distance = sqrt((difference.dx * difference.dx) + (difference.dy * difference.dy)) * 0.02
- camera?.position.x += difference.dx * distance * 0.02
- camera?.position.y -= difference.dy * distance * 0.02
- }
- private var difference = CGVector()
- private var touching: Bool = false
- private var fade: CGFloat = 0
- private func touched(_ touch: UITouch) {
- let pos = touch.location(in: view)
- let center = view!.center
- difference = CGVector(dx: pos.x - center.x, dy: pos.y - center.y)
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- touching = true
- touched(touches.first!)
- }
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
- touched(touches.first!)
- }
- override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
- touching = false
- touched(touches.first!)
- }
- override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
- touching = false
- }
- override func update(_ currentTime: TimeInterval) {
- if touching {
- if fade < 0.02 { fade += 0.0005 }
- } else {
- if fade > 0 { fade -= 0.0005 }
- }
- let distance = sqrt((difference.dx * difference.dx) + (difference.dy * difference.dy)) * 0.01
- camera?.position.x += difference.dx * distance * fade
- camera?.position.y -= difference.dy * distance * fade
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement