-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathViewController.swift
More file actions
84 lines (60 loc) · 2.29 KB
/
ViewController.swift
File metadata and controls
84 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// ViewController.swift
// ARSpriteKit
//
// Created by Esteban Herrera on 7/4/17.
// Copyright © 2017 Esteban Herrera. All rights reserved.
//
import UIKit
import SpriteKit
import ARKit
class ViewController: UIViewController, ARSKViewDelegate {
@IBOutlet var sceneView: ARSKView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and node count
sceneView.showsFPS = true
sceneView.showsNodeCount = true
let scene = Scene(size: sceneView.bounds.size)
scene.scaleMode = .resizeFill
sceneView.presentScene(scene)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
//configuration.planeDetection = .horizontal
// Run the view's session
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
func randomInt(min: Int, max: Int) -> Int {
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
}
// MARK: - ARSKViewDelegate
func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
let ghostId = randomInt(min: 1, max: 6)
let node = SKSpriteNode(imageNamed: "ghost\(ghostId)")
node.name = "ghost"
return node
}
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}