Post

Replies

Boosts

Views

Activity

Reply to Am having problems adding a user-defined setting
Preprocessor defines are specified in build settings under "Other C flags". You would add something like -DMYSCENE. Huh, there it doesn't work. I found Other C Flags, selected DEBUG clicked to ADD CONDITIONAL SETTING and it didn't work from there. To be safe I tried it with and without the -D I even used cut and paste so there would be no typo errors I know Xcode has been under quite a few changes, am using version 12.1 (in was that makes a difference)
Nov ’20
Reply to Am having problems adding a user-defined setting
In Swift, they are compilation conditions, and defined by SWIFTACTIVECOMPILATIONCONDITIONS. Hope you don't mind, but while it works, I still want to make sure I put it where I should. Project -> Build Settings -> All > (search) "Active Compilation" select Active Compilation Conditions click + select Add Conditional Setting under Debug there is now this additional line : Any Architecture | Any SDK ______________ MYSCENE_______________ MYSCENE Again, does work, but it wouldn't be my first time get the result I want but doing it incorrectly p.s. I can only add one. I try to add a second one, and it overwrites the first. Can't see how to insert it.
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
userInteractionEnabled set to NO on a parent view will cascade down to all subviews. If you need some subviews to have interaction enabled, but not others, you can separate your subviews into two parent views: one with userInteractionEnabled = YES and the other NO.  So....it appears that if I do the following for every child : isUserInteractionEnabled = false and ONLY set it to true for GameScene (the parent) That I get the cascade of touches, and can for loop through the nodes. Was that what I was doing wrong? Was it that simple of an error? If so I am both relieved and furious with myself at the same time.
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
All it does is make sure I get touches for the screen itself, not its childrenTrue. And the method touchesBegan(:with:) defined in GameScene detect touches for the scene, not its children. But that's the thing, I need to get the touches for the children, which I was doing before I decided to clean everything up. I've zipped the real sloppy version and it's here if you'd like to try: warptv.com/DropSlot.zip_ Only GameScene has touchesBegan, but it gets all the touches for the balls, which is what I want. Yet, I hav no idea how I lost it. p.s. better to run it on a n iPhone X simulator...hadn't worked on resizing here. p.p.s. Please excuse how sloppy all the code is...it was my first attempt
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
Also for the sample code I uploaded today, I somehow left out the code below (in GVC) and call it right after I create 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) 		 }
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
Ok, have it down to three files, and am not receiving touchesBegan for the red ball. I'd rather it be something stupid I did and be scolded for that GVC import SpriteKit import SwiftUI class GameViewController: UIViewController { &#9;&#9;public let myView : SKView = { &#9;&#9;&#9;&#9;let myView = SKView() &#9;&#9;&#9;&#9;myView.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;&#9;&#9;return myView &#9;&#9;}() &#9;&#9;override func viewDidLayoutSubviews() { &#9;&#9;&#9;&#9;super.viewDidLayoutSubviews() &#9;&#9;&#9;&#9;if myGlobalVars.safeSceneRect == .zero { &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.sceneRect = view.frame &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.sceneRect = myView.frame &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if #available(iOS 11.0, *) { &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.topSafeArea&#9;&#9;= view.safeAreaInsets.top &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.bottomSafeArea = view.safeAreaInsets.bottom &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.topSafeArea&#9;&#9;= topLayoutGuide.length &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.bottomSafeArea = bottomLayoutGuide.length &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if myGlobalVars.gameScene == nil { &#9;&#9;&#9;&#9;&#9;&#9;let scene = GameScene(size: myView.frame.size ) &#9;&#9;&#9;&#9;&#9;&#9;scene.anchorPoint = CGPoint(x: 0.0, y: 0.0) &#9;&#9;&#9;&#9;&#9;&#9;scene.backgroundColor&#9; = .clear &#9;&#9;&#9;&#9;&#9;&#9;scene.scaleMode&#9;&#9;&#9;&#9; = .aspectFit &#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.gameScene = scene &#9;&#9;&#9;&#9;&#9;&#9;myView.presentScene(scene) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;override func viewWillLayoutSubviews() { &#9;&#9;&#9;&#9;super.viewWillLayoutSubviews() &#9;&#9;} &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;view.addSubview(myView) &#9;&#9;&#9;&#9;myView.isHidden&#9;&#9;&#9;&#9;&#9;&#9; = false &#9;&#9;&#9;&#9;myView.ignoresSiblingOrder&#9;= true &#9;&#9;&#9;&#9;myView.showsFPS&#9;&#9;&#9;&#9;&#9;&#9; = true &#9;&#9;&#9;&#9;myView.showsNodeCount&#9;&#9;&#9; = true &#9;&#9;&#9;&#9;myView.showsPhysics&#9;&#9;&#9;&#9; = true &#9;&#9;} &#9; &#9;&#9;override var shouldAutorotate: Bool { &#9;&#9;&#9;&#9;return false &#9;&#9;} &#9;&#9;override var supportedInterfaceOrientations: UIInterfaceOrientationMask { &#9;&#9;&#9;&#9;if UIDevice.current.userInterfaceIdiom == .phone { &#9;&#9;&#9;&#9;&#9;&#9;return .portraitUpsideDown &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;return .all &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;override var prefersStatusBarHidden: Bool { &#9;&#9;&#9;&#9;return false &#9;&#9;} } GC import SpriteKit import SwiftUI struct GlobalVars{ &#9;&#9;var backGround&#9;&#9;&#9;: SKSpriteNode? &#9;&#9;var sceneRect&#9;&#9;&#9; : CGRect &#9;&#9;var safeSceneRect&#9; : CGRect &#9;&#9;var gameScene&#9;&#9;&#9; : GameScene? &#9;&#9;var topSafeArea&#9;&#9; : CGFloat &#9;&#9;var bottomSafeArea&#9;: CGFloat } struct ScreenDimensions{ &#9;&#9;var widthPix&#9;&#9;&#9;&#9;: CGFloat &#9;&#9;var heightPix&#9;&#9;&#9; : CGFloat &#9;&#9;var widthPts&#9;&#9;&#9;&#9;: CGFloat &#9;&#9;var heightPts&#9;&#9;&#9; : CGFloat } var myGlobalVars = GlobalVars(backGround: nil, sceneRect: .zero, safeSceneRect: .zero, gameScene: nil, topSafeArea: 0.0, bottomSafeArea: 0.0) class GameScene: SKScene, SKPhysicsContactDelegate{ &#9;&#9;override func sceneDidLoad(){ &#9;&#9;&#9;&#9;super.sceneDidLoad() &#9;&#9;&#9;&#9;&#9;&#9;print ("GC sceneDidLoad") &#9;&#9;} &#9;&#9; &#9;&#9;override func didMove(to view: SKView){ &#9;&#9;&#9;&#9;super.didMove(to: view) &#9;&#9;&#9;&#9;physicsWorld.contactDelegate = self &#9;&#9;&#9;&#9;self.isHidden = true &#9;&#9;&#9;&#9;myGlobalVars.backGround = SKSpriteNode(imageNamed: "background") &#9;&#9;&#9;&#9;myGlobalVars.backGround!.zPosition = -1 &#9;&#9;&#9;&#9;myGlobalVars.safeSceneRect = view.frame &#9;&#9;&#9;&#9;myGlobalVars.gameScene = self &#9;&#9;&#9;&#9;self.isHidden = false &#9;&#9;&#9;&#9;self.isUserInteractionEnabled = false &#9;&#9;&#9;&#9;self.addChild(myGlobalVars.backGround!) &#9;&#9;&#9;&#9;let myAll = MyGem() &#9;&#9;&#9;&#9;self.addChild(myAll) &#9;&#9;} &#9;&#9; &#9;&#9; &#9;&#9;override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ &#9;&#9;&#9;&#9;super.touchesBegan(touches, with: event) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("touches began") &#9;&#9;&#9;&#9;#endif &#9;&#9;} } Gem import Foundation import SpriteKit class MyGem : SKSpriteNode{ &#9;&#9;init(){ &#9;&#9;let skTexture = SKTexture(imageNamed: "gem_red") &#9;&#9;&#9;&#9;super.init(texture: skTexture, color: .clear, size: CGSize(width: 67, height: 67)) &#9;&#9;self.anchorPoint = CGPoint(x: 0.5, y: 0.5) &#9;&#9;self.size = CGSize(width: 67, height: 67) &#9;&#9;self.zPosition = 2 &#9;&#9;self.position = CGPoint(x: 0, y: 0 ) &#9;&#9;self.position = CGPoint(x: 67/2 + 50, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; y: 67/2 + 50) &#9;&#9;self.size = CGSize(width: 67, height:&#9;67) &#9;&#9;self.isHidden = false; &#9;&#9;self.isUserInteractionEnabled = true &#9;&#9;} &#9;&#9; &#9;&#9;required init?(coder aDecoder: NSCoder) { &#9;&#9;&#9;&#9;fatalError("init(coder:) has not been implemented") &#9;&#9;} }
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
Then do you get the prints in touchesBegan ? Nope, although if put the touchesBegan in the class I am touching, it gets triggered. Even though only GameScene has SKPhysicsContactDelegate and physicsWorld.contactDelegate = self So, why don't you set userInteraction to true ?!?  I do, what I meant by reduced code was so it could be posted, so I was due to delete something I shouldn't have. But just in the post. OK, I did not see "I do" was the answer, looked at it as part of the comment. So, you added a super.touchesBegan in touchesBegan. My turn to say, I didn't catch that. I thought you meant super. in the functions in the class. So now I know to put them in the touches events. Didn't fix it, but thank you for letting me know it needs to be done. Sorry if my reply seemed snippy. It's just that I got my app to a certain point, while learning Swift, and everything worked. So I stopped at a certain point and decided to clean up the code, add comments, make it clean, etc. etc. And I'm so ****** at myself for not testing after each cleanup that I did, and my backups of the clean code doesn't contain a working version. So I have no other option but to start the cleanup again. I'm going to start all over, and make sure test every 5 minutes.....argh
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
What I did just try, was to take my lastest code, the one not working, and I copied over a touchesBegan, with print statements, to redSprite.swift. Lo and behold, it is the one receiving the touches signals. I've checked a million times...only GameScene has: SKPhysicsContactDelegate physicsWorld.contactDelegate = self&#9; I am making sure I call super.init on the redSprite class and it is being added as a child to GameScene. What I broke, I have no clue
Nov ’20
Reply to I have somehow lost the ability to receive touch notifications
Do you call super in each function ? I said I do, if you lookout the post. Did you try to add the print statements ? While the breakpoints showed me when I would or would not receive touch statements, I took your advice and added print statements (easier) Why do you create a new child each time you move ? I answered that as well..... the code you're looking at is a reduction of my actual code, so that I could post it. So there will be slight errors such as that. If I didn't reduce the code...I would have to post a bunch of separate files. So I reduced it into just GameScene so the error still existed
Nov ’20
Reply to Need clarity on lifecycles for UIViewController and SKScene
The output you have shown is exactly the same as what I expect from your code. I do not understand what you expected. Just wanted to make sure it was folding out the right way. The last problem you helped me kind of gave me an epiphany: The last time I coded I was using the WindowsSDK. I understood how that flowed. I knew how it flowed when one window would start another. But am totally new to Swift, and iOS. I was able to find the lifecycle of UIViewContrller, but not for SKScene.
Nov ’20