Post

Replies

Boosts

Views

Activity

Reply to Am having trouble moving code into a separate function
While the code in the OP works, I moved everything screen dimension related to be run in the viewDidLayoutSubviews (which is where it should be) and at that moment I was able to move this code: private func addConstraints(){ 		var constraints = [NSLayoutConstraint]() 		constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } into it's own function, that I could then successfully call. I'm going to assume that my problem was trying do all this before viewDidLayoutSubviews and that's why I couldn't move it to its own function? Although am shocked it worked before since I called it too early. Going to wait for your thoughts before I close this thread.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Am having trouble moving code into a separate function
That is the whole code, at the very bottom of the OP. GameScene itself is empty currently. The only two outside functions I call are: func getScreenDimensions (screen : inout ScreenDimensions) { 		screen.widthPix		 = UIScreen.main.nativeBounds.width 		screen.heightPix		= UIScreen.main.nativeBounds.height 		screen.widthPts		 = UIScreen.main.bounds.width 		screen.heightPts		= UIScreen.main.bounds.height } func setViewAttributes(view: UIView) { 		view.alpha								= 0.0 		view.frame.size.height		= UIScreen.main.nativeBounds.height 		view.frame.size.width		 = UIScreen.main.nativeBounds.width 		view.translatesAutoresizingMaskIntoConstraints = false 		view.backgroundColor			= .clear } Which work
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to I have two objects colliding that shouldn't be
I appreciate that you tried to answer my question with no code. Sadly, the container has no physicsbody. And I can't condense this huge project into paste-able code. So I'm just going to have to rebuild. But if I may pick your brain for a couple of thoughts? If without the code you can't I understand 1 - I removed the safeAreaLayout constraints, and that didn't help but what intrigues me is.... 2 - If I increase the ball axes each by 15, no contact. 3 - The edge borders I use are set at width-1 and height-1 If I make them -15, -15... there is contact. So I'm wondering if edge based SKPhysics body have something different that I'm not aware of.
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’20
Reply to I can get GameScene:SKScene to appear using the layout constraints, but why can I still draw inside the safe ares?
Ok, I went back and forth on OOper's advice, and after repeated errors I finally came across the right combination, by accident. GameViewController launches the scene GameScene, which respects the constraints/safeAreaLayouts. However, it's a mish-mash of using myView and view. While it works, am not sure why, because reading it kind of seems disjointed. I get the constraints from view, but launch from the sub-view myView. Am I getting lucky? Or is this bound to crash? import UIKit import SpriteKit import GameplayKit var myGlobalVars = GlobalVars(backGround: SKSpriteNode(), 															pegHolder: SKSpriteNode(), currentNode: SKSpriteNode(), 															widthPoints: 0.0, heightPoints: 0.0, 															widthPixels: 0.0, heightPixels: 0.0, passGo: false, sceneRect: .zero, fileName: " ") class GameViewController: UIViewController { 		private let myView : UIView = { 				let myView = UIView() 				myView.translatesAutoresizingMaskIntoConstraints = false 				myView.backgroundColor = .clear 				return myView 		}() 		 		private func addConstraints(){ 				var constraints = [NSLayoutConstraint]() 				 				constraints.append(myView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) 				constraints.append(myView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) 				constraints.append(myView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) 				constraints.append(myView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) 				 				NSLayoutConstraint.activate(constraints) 		} 		 		override func viewDidLayoutSubviews() { 				super.viewDidLayoutSubviews() 				let topSafeArea: CGFloat 				let bottomSafeArea: CGFloat 				if #available(iOS 11.0, *) { 						topSafeArea = view.safeAreaInsets.top 						bottomSafeArea = view.safeAreaInsets.bottom 				} else { 						topSafeArea = topLayoutGuide.length 						bottomSafeArea = bottomLayoutGuide.length 				} 		} 		let logo = UIImage(named: "startup") 		override func viewDidLoad() { 				super.viewDidLoad() 				view.addSubview(myView) 				addConstraints() 				 				if let view = self.view as! SKView? 				{ 						 						myGlobalVars.widthPixels = UIScreen.main.nativeBounds.width 						myGlobalVars.heightPixels = UIScreen.main.nativeBounds.height 						myGlobalVars.widthPoints = UIScreen.main.bounds.width 						myGlobalVars.heightPoints = UIScreen.main.bounds.height 						var scene : GameScene! 						DispatchQueue.main.async { [self] in 										 scene = GameScene(size: CGSize(width: myView.frame.width, 																											 height: myView.frame.height)) 						scene.anchorPoint = CGPoint(x: 0.0, y: 0.0) 								scene.backgroundColor = .clear 								scene.scaleMode = .aspectFit 								myGlobalVars.sceneRect = scene.frame 								myGlobalVars.gameScene = scene 								view.isHidden = false 								view.presentScene(scene) 						} 						myGlobalVars.passGo = true 						 						view.ignoresSiblingOrder = true 						view.showsFPS = true 						view.showsNodeCount = true 				} 		} 		 		override var shouldAutorotate: Bool { 				return false 		} 		override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 				if UIDevice.current.userInterfaceIdiom == .phone { 						return .allButUpsideDown 				} else { 						return .all 				} 		} 		override var prefersStatusBarHidden: Bool { 				return false 		} }
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’20
Reply to Can I make a hollow SKPhysicsBody?
I believe I have solved my problem. What I did was essentially use SKContraint to nail each child to it's original spot in the parent. It seems to work and I hope that this is the correct answer. The code below is run at each child's creation 				let rangeX = SKRange(lowerLimit: indexSpacing, upperLimit: indexSpacing) 				let contraintX = SKConstraint.positionX(rangeX) 				let rangeY = SKRange(lowerLimit: (self.size.height/2), upperLimit: (self.size.height/2)) 				let contraintY = SKConstraint.positionY(rangeY) 				self.constraints = [contraintX, contraintY]
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20