Post

Replies

Boosts

Views

Activity

Reply to Having problems subclassing an CGpath as an SKShape
I've been throwing everything I can, hoping something will stick. CGPath(rect: .zero, transform: nil) Produces: Incorrect argument label in call (have 'rect:transform:', expected 'rect:cornerRadius:') Replace 'transform' with 'cornerRadius' Which I do, finally resulting in: super.init(rect: .zero, cornerRadius: CGFloat(0.0)) And the error I get is: Must call a designated initializer of the superclass 'SKShapeNode'
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
Can you show the code of the definition of theZ? Please include all the parts modifying it. Of course, here's my entire DataObjects file. It's just an enum, never gets changed. Line 57 import UIKit import SpriteKit let myVer					 = ver.free var myCurrentLevel	= 1 var screenDims = ScreenDimensions(	widthPix		: 0.0, 																		heightPix	 : 0.0, 																		widthPts		: 0.0, 																		heightPts	 : 0.0) struct ScreenDimensions{ 		var widthPix				: CGFloat 		var heightPix			 : CGFloat 		var widthPts				: CGFloat 		var heightPts			 : CGFloat } struct GlobalVars{ 		var backGround			: SKSpriteNode 		var gemBase				 : SKSpriteNode 		var currentNode		 : SKSpriteNode 		 		var widthPoints		 : CGFloat 		var heightPoints		: CGFloat 		var widthPixels		 : CGFloat 		var heightPixels		: CGFloat 		 		var sceneRect			 : CGRect 		var safeSceneRect	 : CGRect 		var gameScene			 : GameScene 		var currentGem			: SKSpriteNode 		var fileName				: String 		 		var topSafeArea		 : CGFloat 		var bottomSafeArea	: CGFloat 		var domHand				 : DominantHand } enum bodyMasks: UInt32 { 		case blankMask							= 0b0 		case slotMask							 = 0b1 		case gemBaseMask						= 0b10 		case borderMask						 = 0b100 		case guessBarMask					 = 0b1000 		case guessSlotMask					= 0b10000 		case gemMask								= 0b100000 		case edgeMask							 = 0b1000000 } enum ver { 		case free 		case paid } struct zPositions { 		let controler			 : CGFloat	 = -2 		let background			: CGFloat	 = -1 		let gemBase				 : CGFloat	 = 0 		let theBoarder			: CGFloat	 = 0 		let guessBar				: CGFloat		= 0 		let guessGemBase		: CGFloat	 = 0 		let guessSlot			 : CGFloat	 = 1 		let gem						 : CGFloat	 = 1 } enum Gems { 		case red 		case yellow 		case blue 		case green 		case aqua 		case orange } enum NodeType : Int { 		case gem = 0, 				 border, 				 guessBar, 				 guessSlot, 				 edge } enum GemStatus : Int { 		case home = 0, moving, guessed } let GemColors :[Gems] = [ 		.red, 		.yellow, 		.blue, 		.green, 		.aqua, 		.orange]
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
First block is GVC Second is GC You'll notice that I commented out your let scene= and put back in my DispatchQueue. That's the only way it works. Right now, the only thing that GC is doing is pulling up a blue background.png (when I remove DispatchQueue and use your let scene = the blue background never shows up GVC import UIKit import SpriteKit class GameViewController: UIViewController { 		 		public let myView : SKView = { 				let myView = SKView() 				myView.translatesAutoresizingMaskIntoConstraints = false 				return myView 		}() 		private func addConstraints(){ 				 var constraints = [NSLayoutConstraint]() 				//add 				 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)) 				//activate 				 NSLayoutConstraint.activate(constraints) 		 } 		override func viewDidLoad() { 				super.viewDidLoad() 				#if DEBUG 						print ("GVC viewDidLoad") 				#endif 				 //				if let view = self.view as! SKView? 						 						view.addSubview(myView) 						addConstraints() 						var scene : GameScene! //				var scene = GameScene(size: myView.frame.size) //				let scene = GameScene(size: myView.frame.size) 						DispatchQueue.main.async { [self] in scene = GameScene(size: myView.frame.size ) 								 								scene.anchorPoint = CGPoint(x: 0.0, y: 0.0) 								scene.backgroundColor	 = .clear 								scene.scaleMode				 = .aspectFit 								myView.isHidden					 = false 								myView.ignoresSiblingOrder		= true 								myView.showsFPS							 = true 								myView.showsNodeCount				 = true 								myView.showsPhysics					 = true 								myView.presentScene(scene) 						} 				 		} 		override func viewWillLayoutSubviews() { 				super.viewWillLayoutSubviews() 		} 		override func viewDidLayoutSubviews() { 				super.viewDidLayoutSubviews() 				#if DEBUG 						print ("GVC viewDidLayoutSubviews") 				#endif 				getScreenDimensions (screen: &screenDims) 				if myGlobalVars.safeSceneRect == .zero { 						myGlobalVars.sceneRect = view.frame 						myGlobalVars.sceneRect = myView.frame 				} 				 				if #available(iOS 11.0, *) { 						myGlobalVars.topSafeArea		= view.safeAreaInsets.top 						myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom 				} else { 						myGlobalVars.topSafeArea		= topLayoutGuide.length 						myGlobalVars.bottomSafeArea = bottomLayoutGuide.length 				} 		} 		 		override var shouldAutorotate: Bool { 				return false 		} 		override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 				if UIDevice.current.userInterfaceIdiom == .phone { 						return .portraitUpsideDown 				} else { 						return .all 				} 		} 		override var prefersStatusBarHidden: Bool { 				return false 		} } GC import UIKit import SpriteKit var myBorder = SKSpriteNode() class GameScene: SKScene, SKPhysicsContactDelegate { 		override func sceneDidLoad(){ 				super.sceneDidLoad() 			 self.isUserInteractionEnabled = true 		} 		override func didMove(to view: SKView){ 				super.didMove(to: view) 				myGlobalVars.backGround = SKSpriteNode(imageNamed: "background") 				myGlobalVars.backGround.zPosition = theZ.background 				self.isHidden = false 				self.addChild(myGlobalVars.backGround) 				myGlobalVars.safeSceneRect = view.frame 				myGlobalVars.backGround.zPosition = theZ.background 				myGlobalVars.gameScene = self 		} }
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
Add another method to GameScene and move some processing into it which needs to run after some event is finished. And call the method in your GameViewController from some method which surely runs after the event. I was using a 1 second sleep timer loop in GameScene until GameViweController's last line of code was setting a flag to cancel the loop. but I thought that was too kludgy. In this case, you need to keep the scene as a new property of GameViewController, and use it instead of myView.scene. Now that you mention it, I'm not find any code to link GameScene to GameViewcontroller. Only posts I found said "don't run any other code in GVC, after launching GameScene. I hope that's right. Going to mark this question answered by end of night, so I know you've read this. My other question is going into its own thread
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
OOper .... there aren't enough letters in the alphabet to thank you, not only for going through all the trouble to edit my code, but for showing me that I had to change the class of Main.storyboard. I pulled out my source code from a few days (where I got the error below). Once I made that one change to the storyboard, it all worked. Before when I tried creating myView as an SKView I always got this error Cannot convert return expression of type 'UIView' to return type 'SKView' Side note: When I changed the class in storyboard to UIView, it was not available in the dropdown list. I had to type it in manually. On some other boards and/or posts I was told SKView couldn't apply constraints. Don't worry am going to check your answer soon, I just need to clarify two things you changed: calling addContraints() in viewDidLoad I can posts a bunch of links that say that bounds are not guaranteed to be set in viewDidLoad and to wait till viewDidLayoutSubviews Also, I noticed you removed my calling GameScene from a thread. That was used because GameScene routines were running ahead of schedule. So someone told me to use DispatchQueue.main.async. Can I go back to that? As for why I left Main.storyboard, I'll start another post for that
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
(complete code for GameViewController is at the bottom) Sorry, but I do not understand what you mean by restraints. I am not saying to set restraints something. Just saying to change the type of myView to SKView I meant setting the safeAreaLayout constraints, so that every screen will fall within the proper edges of the screen (iPhoneX). SKView appears to have no process to do that. Have you really removed Main.storyboard from your project? No, I couldn't. So it's still there and Main storyboard filename is set to Main within info.plist. If you're about to tell me that setting safeArea in Main.storyboard will take care of every screen...you're going hear me cry no matter where you are. And not using storyboards has nothing to do with changing the type of myView. Am only using myView as a UIView to set safeAreaLayout. If I can set SafeAreaLayout for every screen somewhere else, I wouldn't use myView at all. p.s. Would love to know how you're changing some text color here in the forum, makes reading these replies easier import UIKit import SpriteKit class GameViewController: UIViewController { 		 		public let myView : UIView = { 				let myView = UIView() 				return myView 		}() 		private func addConstraints(){ 				 var constraints = [NSLayoutConstraint]() 				//add 				 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)) 				//activate 				 NSLayoutConstraint.activate(constraints) 		 } 		override func viewDidLoad() { 				super.viewDidLoad() 				 				if let view = self.view as! SKView? { 						 						view.addSubview(myView) 						var scene : GameScene! 						DispatchQueue.main.async { scene = GameScene(size: CGSize(width: screenDims.widthPts - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, height: screenDims.heightPts-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom)) 								myGlobalVars.widthPoints = screenDims.widthPts - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right 								myGlobalVars.heightPoints = screenDims.heightPts - self.view.safeAreaInsets.top - self.view.safeAreaInsets.bottom 								#if DEBUG 										print("SIZE \(screenDims.heightPts)") 										print("SIZE \(self.view.safeAreaInsets.top)") 										print("SIZE \(self.view.safeAreaInsets.bottom)") 								#endif 								 								scene.anchorPoint = CGPoint(x: 0.0, y: 0.0) 								scene.backgroundColor	 = .clear 								scene.scaleMode				 = .aspectFit 								view.isHidden					 = false 								view.presentScene(scene) 						} 						view.ignoresSiblingOrder		= true 						view.showsFPS							 = true 						view.showsNodeCount				 = true 						view.showsPhysics					 = true 				} 		} 		override func viewWillLayoutSubviews() { 				super.viewWillLayoutSubviews() 				#if DEBUG 						print ("GVC viewWillLayoutSubviews") 				#endif 				let constraints = [ 						view.centerXAnchor.constraint(equalTo: view.centerXAnchor), 						view.centerYAnchor.constraint(equalTo: view.centerYAnchor), 						view.widthAnchor.constraint(equalToConstant: 100), 						view.heightAnchor.constraint(equalTo: view.widthAnchor)] 				NSLayoutConstraint.activate(constraints) 		} 		override func viewDidLayoutSubviews() { 				super.viewDidLayoutSubviews() 				getScreenDimensions (screen: &screenDims) 				if myGlobalVars.safeSceneRect == .zero { 						addConstraints() 						createConstraints(view: myView) 						myGlobalVars.sceneRect = view.frame 				} 				 				if #available(iOS 11.0, *) { 						myGlobalVars.topSafeArea		= view.safeAreaInsets.top 						myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom 				} else { 						myGlobalVars.topSafeArea		= topLayoutGuide.length 						myGlobalVars.bottomSafeArea = bottomLayoutGuide.length 				} 		} 		 		override var shouldAutorotate: Bool { 				return false 		} 		override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 				if UIDevice.current.userInterfaceIdiom == .phone { 						return .portraitUpsideDown 				} else { 						return .all 				} 		} 		override var prefersStatusBarHidden: Bool { 				#if DEBUG 						print ("GVC prefersStatusBarHidden") 				#endif 				return false 		} }
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
You usually add a subview and add constraints to it inside viewDidLoad(). Yikes! Yup, didn't take that into account...that would be recursivly bad. Thanks. You need to change the type of myView from UIView to  SKView, as I wrote once in another thread of yours. Except that there is no restraint for SKViews...can't find it, and have been told in more than one post there is no way to set restraints for SKViews. In SpriteKit games, you usually create a fixed size GameScene (SKScene) and make iOS scale it for the view. And there's the bottom line. I have found no way to create the GameScene size fixed other than getting constraints from myView(UIView). And remember, am not using storyboards at all.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to I have a question about using self.view.safeAreaInsets in GameViewController
NO.If you add right constraints between the main view of the UIViewController and a view (myView), it should work. So, you have no need to search for equivalent. This is what I was using...found it from posts. And someone told me that that was absolutely bad, and that it would eventually ** up in my face. What I did was: GameViewController (viewWillLayoutSubviews) Created an UIView Made it a subView of GameViewController Got all constraints, from UIView, and applied them Then still within GVC** I created GameScene using the values I got from constraints I noticed tho, I don't add the GameScene to any view. Is that wrong?
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’20
Reply to Am having trouble moving code into a separate function
Then you should better go back to your old thread: I can get GameScene:SKScene to appear using the layout constraints, but why can I still draw inside the safe ares? - https://www.example.com/You have gone for a wrong direction too far, that's why many of your codes do not work as expected. I have gone back to that, Googled some more, and found how to get the safeAreaLayout for the GameViewControler itself, code below, so I can skip the myView part, . But that itself brings up two issues... Should I start another thread?override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() #if DEBUG print ("GVC viewWillLayoutSubviews") #endif let safeAreaInsets = self.view.safeAreaInsets; }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Am having trouble moving code into a separate function
For instance, why do you initialize myGlobalVars in viewDidLayoutSubviews ? Thank you for pointing that out. Claude31, Yes need to move that to viewDidLoad I strongly recommend not to add subview, not to change or add constraints in viewDidLayoutSubviews. Hello OOper, you've been super helpful before. May I ask why? Every video, or online posts say that when viewDidLayoutSubviews is called, that that's when you can be guaranteed that the scene's dimensions are set properly. The reason I add a subView was because I couldn't call the constraints on GameViewController. If I am doing this wrong, would love to hear how I should be doing it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Am having trouble moving code into a separate function
After going through the code, over and over I realized I was calling the safeAreaLayout routine before viewDidLayoutSubviews. Now I can move my call to a function and it works. Now I'd love to know why it was working before, when I was calling it prematurely. But maybe I should be grateful that I found a substantial error. So now my code looks the same as the code in the OP, except every call regarding screen dimensions, and safeAreaLayout, are done in the viewDidLayoutSubviews function. And addConstraints is now an external function override func viewDidLayoutSubviews() { 		super.viewDidLayoutSubviews() 		getScreenDimensions (screen: &screenDims) 		view.addSubview(myView) 		addConstraints() 		myGlobalVars.sceneRect = view.frame 		createConstraints(view: myView) 		 		if #available(iOS 11.0, *) { 				myGlobalVars.topSafeArea		= view.safeAreaInsets.top 				myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom 		} else { 				myGlobalVars.topSafeArea		= topLayoutGuide.length 				myGlobalVars.bottomSafeArea = bottomLayoutGuide.length 		} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20