diff --git a/Prism Refraction.xcodeproj/project.pbxproj b/Prism Refraction.xcodeproj/project.pbxproj index b175fd5..ed78707 100644 --- a/Prism Refraction.xcodeproj/project.pbxproj +++ b/Prism Refraction.xcodeproj/project.pbxproj @@ -283,14 +283,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = N8VX7T6P4D; + DEVELOPMENT_TEAM = M3WBMTG67K; INFOPLIST_FILE = "Prism Refraction/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.rugyron.Prism-Refraction"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rugyron.Prism-Refraction2"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -302,14 +302,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = N8VX7T6P4D; + DEVELOPMENT_TEAM = M3WBMTG67K; INFOPLIST_FILE = "Prism Refraction/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.rugyron.Prism-Refraction"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rugyron.Prism-Refraction2"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/Prism Refraction.xcodeproj/project.xcworkspace/xcuserdata/alexeyvoronov.xcuserdatad/UserInterfaceState.xcuserstate b/Prism Refraction.xcodeproj/project.xcworkspace/xcuserdata/alexeyvoronov.xcuserdatad/UserInterfaceState.xcuserstate index 777b068..980479d 100644 Binary files a/Prism Refraction.xcodeproj/project.xcworkspace/xcuserdata/alexeyvoronov.xcuserdatad/UserInterfaceState.xcuserstate and b/Prism Refraction.xcodeproj/project.xcworkspace/xcuserdata/alexeyvoronov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Prism Refraction/ViewController.swift b/Prism Refraction/ViewController.swift index 280457d..f203784 100644 --- a/Prism Refraction/ViewController.swift +++ b/Prism Refraction/ViewController.swift @@ -21,6 +21,8 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { var t1h = Int() var t2h = Int() + var currentNode : SKNode? + override func viewDidLoad() { super.viewDidLoad() let sceneView = SKView(frame: self.view.bounds) @@ -30,26 +32,13 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { sceneView.isMultipleTouchEnabled = true sceneView.presentScene(scene) sceneView.showsFPS = true - sceneView.showsPhysics = false + sceneView.showsPhysics = true self.view.addSubview(sceneView) - addWall(a: CGPoint(x: 325, y: 300), b: CGPoint(x: 50, y: 300)) - addWall(a: CGPoint(x: 325, y: 200), b: CGPoint(x: 50, y: 200)) - - addWall(a: CGPoint(x: 325, y: 300), b: CGPoint(x: 325, y: 200)) - addWall(a: CGPoint(x: 50, y: 300), b: CGPoint(x: 50, y: 200)) - - addWall(a: CGPoint(x: 325, y: 600), b: CGPoint(x: 50, y: 600)) - addWall(a: CGPoint(x: 325, y: 500), b: CGPoint(x: 50, y: 500)) - - addWall(a: CGPoint(x: 325, y: 600), b: CGPoint(x: 325, y: 500)) - addWall(a: CGPoint(x: 50, y: 600), b: CGPoint(x: 50, y: 500)) - - addWall(a: CGPoint(x: 50, y: 400), b: CGPoint(x: 375/2, y: 450)) - addWall(a: CGPoint(x: 375/2, y: 450), b: CGPoint(x: 325, y: 400)) - addWall(a: CGPoint(x: 325, y: 400), b: CGPoint(x: 375/2, y: 350)) - addWall(a: CGPoint(x: 375/2, y: 350), b: CGPoint(x: 50, y: 400)) + addFigure(id: 2, pos: CGPoint(x: 100, y: 100)) + addFigure(id: 1, pos: CGPoint(x: 0, y: 0)) + addFigure(id: 1, pos: CGPoint(x: 100, y: 400)) } @@ -61,7 +50,33 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { } } - func addWall(a: CGPoint, b: CGPoint) { + func addFigure(id: Int, pos: CGPoint) { + let figure = SKNode() + + switch id { + case 1: + figure.addChild(addWall(a: CGPoint(x: -100, y: 0), b: CGPoint(x: 0, y: 50))) + figure.addChild(addWall(a: CGPoint(x: 0, y: 50), b: CGPoint(x: 100, y: 0))) + figure.addChild(addWall(a: CGPoint(x: -100, y: 0), b: CGPoint(x: 0, y: -50))) + figure.addChild(addWall(a: CGPoint(x: 0, y: -50), b: CGPoint(x: 100, y: 0))) + case 2: + figure.addChild(addWall(a: CGPoint(x: -50, y: 0), b: CGPoint(x: 0, y: 50))) + figure.addChild(addWall(a: CGPoint(x: 0, y: 50), b: CGPoint(x: 50, y: 0))) + figure.addChild(addWall(a: CGPoint(x: -50, y: 0), b: CGPoint(x: 50, y: 0))) + default: + figure.addChild(addWall(a: CGPoint(x: -100, y: 0), b: CGPoint(x: 0, y: 50))) + figure.addChild(addWall(a: CGPoint(x: 0, y: 50), b: CGPoint(x: 100, y: 0))) + figure.addChild(addWall(a: CGPoint(x: -100, y: 0), b: CGPoint(x: 0, y: -50))) + figure.addChild(addWall(a: CGPoint(x: 0, y: -50), b: CGPoint(x: 100, y: 0))) + } + + figure.position = pos + figure.name = "draggable" + + scene.addChild(figure) + } + + func addWall(a: CGPoint, b: CGPoint) -> SKNode { let yourline = SKShapeNode() let pathToDraw = CGMutablePath() pathToDraw.move(to: a) @@ -72,7 +87,7 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { yourline.glowWidth = 1.0 yourline.physicsBody = SKPhysicsBody(edgeFrom: a, to: b) yourline.physicsBody?.isDynamic = false - scene.addChild(yourline) + return yourline } func addLine(a: CGPoint, b: CGPoint, hue: CGFloat) { @@ -148,7 +163,22 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { } } + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + if let touch = touches.first { + let location = touch.location(in: self.scene) + + let touchedNodes = self.scene.nodes(at: location) + for node in touchedNodes.reversed() { + if node.name == "draggable" { + self.currentNode = node + } + } + } + } + override func touchesEnded(_ touches: Set, with event: UIEvent?) { + self.currentNode = nil + for touch in touches { if touch.hash == t1h { t1h = 0 @@ -161,6 +191,12 @@ class ViewController: UIViewController, SKViewDelegate, SKSceneDelegate { } override func touchesMoved(_ touches: Set, with event: UIEvent?) { + + if let touch = touches.first, let node = self.currentNode { + let touchLocation = touch.location(in: self.scene) + node.position = touchLocation + } + // state is needed to define if touch is 1 or 2 (2 = true) var state:Bool = false