Post

Replies

Boosts

Views

Activity

Problem again with user-defined setting
This was something I needed so much help with in this post https://developer.apple.com/forums/thread/666997 I want to add a user defined setting. As I did (from the answer in the previous post, I made sure I was adding in SWIFTACTIVECOMPILATION_CONDITIONS I added MYDEBUG01, which does not work. This is in Xcode 12.4 I put up both projects in a picture, the one where it does work is the bottom one, MYSCENES. This was in Xcode 11.x The screens do look a little different, but can't figure out where my error is. Here is the screenshot http:// 98.7.37.117/index.html
2
0
1.7k
Feb ’21
LaunchScreen doesn't show on simulator in Xcode 12.4
I just upgraded to Xcode 12.4, created a project using the "app" template, without SwiftUI, I chose Storyboard instead. I placed a small image on the LaunchScreen.storyboard, and an NSLog output in my ViewController. When I run the app on the simulator, the LaunchScreen does not, show, and I do get my NSLog output. So I know the app is running. When run this bare app on my physical iPhone X...I do get the launch screen. So I opened a game app I started under Xcode 11.x. It will show the LaunchScreen on both simulator and my device. I've checked that Launch screen interface file base name is set to LaunchScreen in Info.plist. It's also set under App Icons and Launch Images. Is this some bug?
5
0
2.6k
Feb ’21
Did Xcode 12.4 get rid of "storyboards" by default?
Haven't touched Xcode since it upgraded to 12.4. Just started a new app, which I planned to create without storyboards. But the default files I am used to deleting or manipulating aren't there anymore. I don't even see AppDelegate.swift. So did Xcode 12.4 get rid of "storyboards" by default? And if so, where do I go to relearn how to start? Thanks.
5
0
3.3k
Jan ’21
Can there be multiple SKNodes in a UITapGestureRecognizer
When I'm dealing with touchesBegan, moved, etc. I am able to loop through every item at the CGPoint where the action occurred. So obviously I am dealing with everything through my GameScene. Now when working with UITapGestureRecognizer, I can't seem to come up with the code that would tell me if there are multiple items at the point of tapping (single tap only). It's not that I want that to happen, but I fear my code may crash if it does occur. Should UITapGestureRecognizer be handled by each SKNode that uses it? Or is there a code solution where I can handle it all through GameScene? Here is how I deal with touches_: override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ &#9;&#9;&#9;&#9;guard let touch = touches.first else { return } &#9;&#9;&#9;&#9;let location = touch.location(in: self) &#9;&#9;&#9;&#9;let touchedNodes = self.nodes(at: location) &#9;&#9;&#9;&#9;for theNode in&#9;touchedNodes{ &#9;&#9;&#9;&#9;&#9;&#9;if let node = theNode as? MyBall { .......my code,...... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;} And here's how I handle UITapGestureRecognizer, yet unable to figure out code to see if there's more than one SKNode: @objc func tappedView(_ sender:UITapGestureRecognizer) { &#9;&#9;if sender.state == .ended{ &#9;&#9;&#9;&#9;let point : CGPoint = sender.location(in: self.view) var post = sender.location(in: sender.view) &#9;&#9;&#9;&#9;post = self.convertPoint(fromView: post) &#9;&#9;&#9;&#9;if let touchNode = self.atPoint(post) as? Ball{ ......my code....... &#9;&#9;&#9;&#9;} &#9;&#9;} }
1
0
260
Dec ’20
Is there a property that detects SKSpriteNode taps vs. movements
My app is very simple. Using all the touchesFunctions, I can drag a ball around the screen I'd also, like the user to be able to tape the ball, then tap where to place it, hence no dragging. Just tap to select the ball, then tap where to send it. I added UITapGestureRecognizer to my code. My problem is that with a tap, touchesBegan and touchesMoved are also triggered. The heavier the user taps, the more touchesMoved are registered. In one test I was able to do an intended tap, and still got 15 touchesMoved before the Tap. Is there an iOS property that can somehow help me? Because the only other choice I see is writing ugly code that has to compare time so a selection My problem is that I don't get the tap trigger till the end. So I can write code to detect time differences, or something else horrendous, or maybe there's a property that can help?
0
0
367
Nov ’20
Is there a way to run a group of SKActions followed by a sequence?
If I have the following SKActions I want done: let spinAction = SKAction.rotate(byAngle: 360, duration: 003) let moveAction = SKAction.move(to: CGPoint(x: origNP.x, y: origNP.y), duration: 0.3) let setFlags = SKAction.run { moveThis.inSlot = true; &#9;&#9;moveThis.isMoving = false; moveThis.inSlot = true} I know I can either run them in sequence: let sequence = SKAction.sequence([spinAction, moveAction, setFlags]) or all at once as a group let group = SKAction.group([spinAction, moveAction, setFlags]) But what if I need to call other sequences, or just reset flags after the sequence or group method is done? Do they have some sort of notifiers after completion?
1
0
229
Nov ’20
Which is the most efficient way to move a ball?
I'm currently have an app with 6 balls. I use. the following method to move a Ball. Once it's touched I set its .isMoving property to true, and save the node that was touched into a global variable. Of course the moment I get a touchesEnded or touchesCanceled, the first thing I do is set the moving property to false, clear the global variable and call a function that animates the ball back to its starting my point. While this all works, I'm too new to Swift to know if this method has any flaws, or is not the proper/efficient way to do this. If it makes any difference am catching all touches, and movements in the GameScene. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ &#9;&#9;guard let touch = touches.first else { return } &#9;&#9;let location = touch.location(in: self) &#9;&#9;let touchedNodes = self.nodes(at: location) &#9;&#9;for node in&#9;touchedNodes{ &#9;&#9;&#9;&#9;if let theNode = node as? SKSpriteNode { &#9;&#9;&#9;&#9;&#9;&#9;if theNode.name == "ball" { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;theNode.zPosition += 1 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;node.isMoving = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){ &#9;&#9;guard touches.first != nil else { return } &#9;&#9; if let touch = touches.first, let node = myGlobalVars.currentBall, node.isMoving == true{ &#9;&#9;&#9;&#9;&#9;let touchLocation = touch.location(in: self) &#9;&#9;&#9;&#9;&#9;node.position = touchLocation &#9;&#9;&#9;&#9;&#9;//redraw node to emulate motion &#9;&#9;&#9;&#9;} &#9;&#9;}
0
0
368
Nov ’20
I have a problem moving an SKSpriteNode, it seems pixel vs. points related
I am trying to place a border on top of a white block. When I set the border's Y positioning only based on the height of the block, I get what I expected: The border is half into the block. Screenshot, top half The next logical step: I adjust the border's Y position to include half of its own height. What I expect is the bar resting on top of the block. But for some reason, the border is way above the block. Screenshot, bottom half Am I somehow confusing pixels for points? When I do take the border's height into account, I use this line: self.position = CGPoint(x: myGV.safeSceneRect.width/2, y: myGV.gemBaseSize.height + (self.size.height/2)) Below in order: My code for the border, Print out of sizes and positions a link to the two screen shots import Foundation import SpriteKit class MyBorder : SKSpriteNode{ &#9;&#9;var nodeType = NodeType.border &#9;&#9;init(){ &#9;&#9;&#9;&#9; //create SKSpriteNode, size it based on screen size &#9;&#9;&#9;&#9;super.init(texture: SKTexture(imageNamed: "border"), color: .clear, size: CGSize(width: myGV.safeSceneRect.width, height: myGV.safeSceneRect.height * 0.07)) &#9;&#9;&#9;&#9;self.anchorPoint = CGPoint(x: 0.5, y: 0.5) &#9;&#9;&#9;&#9;self.isHidden = true &#9;&#9;&#9;&#9;self.isUserInteractionEnabled = false &#9;&#9;&#9;&#9;self.zPosition = theZ.border &#9;&#9;&#9;&#9;self.alpha = 0.5 &#9;&#9;&#9;&#9;// position border on top of block &#9;&#9;&#9;&#9;self.position = CGPoint(x: myGV.safeSceneRect.width/2, y: myGV.blockBaseSize.height) &#9;&#9;&#9;&#9;print("Screen Size \(myGV.safeSceneRect)") &#9;&#9;&#9;&#9;print(“Block Size \(myGV.blockBaseSize)") &#9;&#9;&#9;&#9;print("Border Size \(self.size)") &#9;&#9;&#9;&#9;print("Border Pos \(self.position)") &#9;&#9;&#9;&#9;myGV.gameScene!.addChild(self) &#9;&#9;&#9;&#9;self.isHidden = false &#9;&#9;} &#9;&#9;required init?(coder aDecoder: NSCoder) { &#9;&#9;&#9;&#9;fatalError("init(coder:) has not been implemented") &#9;&#9;} } Here is the output for both runs, same order as the image > Screen Size (0.0, 44.0, 375.0, 734.0) Block Size (300.0, 146.8) Border Size (375.0, 51.380001068115234) Border Pos (187.5, 146.8000030517578) Screen Size (0.0, 44.0, 375.0, 734.0) Block Size (300.0, 146.8) Block Size (375.0, 51.380001068115234) Border Pos (187.5, 172.49000549316406) www .warptv.com/links/screens.png
1
0
287
Nov ’20
How can I pass a function a parameter
Rather than do this: let skTexture = SKTexture(imageNamed: "slot") let mySlot = SKSpriteNode(texture: skTexture, color: .clear, size: slotSize) I would like to grab the texture in the call to create the SKSprite. I know I'm supposed to use closures, yet I am unable to figure out the proper syntax. Am looking for something like: let mSlot = SKSpriteNode( {texture: SKTexture(imageNamed: "slot") -> (SKTexture)} color: SKColor.clear, size: mySlotSize) Have tried as many variants as I can think of but never get to the point where I can compile. If the closure is something that I must predefine, then there's no point in trying this.
2
0
264
Nov ’20
Why would two SKSprite objects that interact even though they don't touch?
My entire project is here www. warptv.com/DropSlot.zip It's very sloppy and kludgy because I made it while I started to learn Swift. In the code I make a pegHolder positioned at 10, 10 The pegHolder contains 6 slots, and each slot holds a different color ball The pegHolder is a child of GameScene The slots are children of the pegHolder and each ball is a child of itsslot Then I create a barrier on the left side of the screen that runs up and down on an X axis of 5 (although in the end I want it at -1. For some reason at setup, the red ball is thrown on the other side of the barrier. I can grab it and pull it back, but it shouldn't start being thrown off the screen. Oddly enough I never register a collision, so it must be something else throwing the ball over. When I tried it with the barrier at the bottom of the screen, the same thing happened. Any thoughts would be appreciated.
1
0
965
Nov ’20
I have somehow lost the ability to receive touch notifications
Two days ago I was able to receive touchesBegan (moved, canceled) and now I've lost them. So I shortened the code below, created an SKSpriteNode called redSprite within GameScene...and still I don't receive touches. While I know my redSprite doesn't fulfill all the if's in the touch functions, I'm placing a breakpoint at the start of the touch functions, and it still won't stop at the breakpoint. However...if I set GameScene's isUserInteractionEnabled to true, then I do get the touches and the debugger breaks. import UIKit import SpriteKit var redSprite : SKSpriteNode? class GameScene: SKScene, SKPhysicsContactDelegate { &#9;&#9;override func sceneDidLoad(){ &#9;&#9;&#9;&#9;super.sceneDidLoad() &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC sceneDidLoad") &#9;&#9;&#9;&#9;#endif &#9;&#9;} &#9;&#9; &#9;&#9;override func didMove(to view: SKView){ &#9;&#9;&#9;&#9;super.didMove(to: view) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC didMove START") &#9;&#9;&#9;&#9;#endif &#9;&#9;&#9;&#9;self.isHidden = true &#9;&#9;&#9;&#9;self.backgroundColor = mySafeColor &#9;&#9;&#9;&#9;myGlobalVars.backGround = SKSpriteNode(imageNamed: "background") &#9;&#9;&#9;&#9;myGlobalVars.backGround!.zPosition = theZ.backGround &#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;physicsWorld.contactDelegate = self &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;redSprite = SKSpriteNode(color: .red, size: CGSize(width: 100, height: 100)) &#9;&#9;&#9;&#9;redSprite?.anchorPoint = CGPoint(x: 0.5, y:0.5) &#9;&#9;&#9;&#9;redSprite?.isHidden = false &#9;&#9;&#9;&#9;redSprite?.isUserInteractionEnabled = true &#9;&#9;&#9;&#9;redSprite?.color = .orange &#9;&#9;&#9;&#9; redSprite!.name = "test" &#9;&#9;&#9;&#9; redSprite?.zPosition = 10 &#9;&#9;&#9;&#9;redSprite?.position = CGPoint(x: (myGlobalVars.safeSceneRect.width/2)-(50), y: myGlobalVars.safeSceneRect.height/2 - 50) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;redSprite?.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 100, height: 100), center: CGPoint(x: 0.5, y: 0.5)) &#9;&#9;&#9;&#9; redSprite?.physicsBody!.affectedByGravity = false &#9;&#9;&#9;&#9; redSprite?.physicsBody!.restitution = 0.2 &#9;&#9;&#9;&#9; redSprite?.physicsBody?.categoryBitMask&#9;&#9;= bodyMasks.blankMask.rawValue &#9;&#9;&#9;&#9; redSprite?.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue &#9;&#9;&#9;&#9; redSprite?.physicsBody?.collisionBitMask&#9; = bodyMasks.blankMask.rawValue &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; self.addChild(redSprite!) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;gameTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: true) &#9;&#9;&#9;&#9;gameTimer?.tolerance = 0.2 &#9;&#9;&#9;&#9;RunLoop.current.add(gameTimer!, forMode: .common) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC didMove END") &#9;&#9;&#9;&#9;#endif &#9;&#9;} &#9;&#9;override func touchesBegan(_ touches: Set<UITouch>, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; with event: UIEvent?){ &#9;&#9;&#9;&#9;guard let touch = touches.first else { return } &#9;&#9;&#9;&#9;let location = touch.location(in: self) &#9;&#9;&#9;&#9;let touchedNodes = self.nodes(at: location) &#9;&#9;&#9;&#9;for node in&#9;touchedNodes{ &#9;&#9;&#9;&#9;&#9;&#9;if let theNode = node as? MyGem { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if theNode.nodeType == NodeType.gem, theNode.isMoving == false { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;theNode.isMoving = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;theNode.zPosition += 1 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;myGlobalVars.currentGem = theNode &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){ &#9;&#9;&#9;&#9;guard touches.first != nil else { return } &#9;&#9;&#9;&#9;if let touch = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { &#9;&#9;&#9;&#9;&#9;&#9;let touchLocation = touch.location(in: self) &#9;&#9;&#9;&#9;&#9;&#9;node.position = touchLocation &#9;&#9;&#9;&#9;&#9;&#9;node.isMoving = true &#9;&#9;&#9;&#9;&#9;&#9;node.inSlot = false &#9;&#9;&#9;&#9;&#9;&#9;//addTrailToTwinkle(theNode: node) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { &#9;&#9;&#9;&#9; guard touches.first != nil else { return } &#9;&#9;&#9;&#9;if let _ = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { &#9;&#9;&#9;&#9;&#9;&#9;returnHome(moveThis : node, origNP: node.origPoint) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { &#9;&#9;&#9;&#9;&#9;&#9;guard touches.first != nil else { return } &#9;&#9;&#9;&#9;&#9;&#9;if let _ = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { &#9;&#9;&#9;&#9;&#9;&#9;returnHome(moveThis : node, origNP: node.origPoint) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9; &#9;&#9;@objc func runTimedCode() { &#9;&#9;&#9;timeLeft -= 1 &#9;&#9;} }
21
0
1.7k
Nov ’20
Need clarity on lifecycles for UIViewController and SKScene
Below is my abbreviated code, the full code does work. It starts at GameViewController, create GameScene, and GameScene creates an SKSpriteNode. What's confusing me is the debug output which just tracks where I am in my app (shown in the abbreviated code). The debug output is at the very bottom of this post. I wonder about the order of execution, the last debug msg is the end of GameViewController...I would have thought I'd be done with that already. i.e. How do I know that everything I'm setting in GVC is setup before it's needed in GC? On a side note, I've tried Googling "SKScene lifecycle" and can't seem to find the proper documentation. GameViewController class GameViewController: UIViewController { &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GVC viewDidLoad") &#9;&#9;&#9;&#9;#endif &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;... create myView (as an SKView) &#9;&#9;&#9;&#9;... add it as a subview of GameViewController &#9;&#9;&#9;&#9;... use myView to get constraints ... and set other properties &#9;&#9;&#9;&#9;myView.isHidden&#9;&#9;&#9;&#9;&#9;&#9; = false &#9;&#9;&#9;&#9;myView.ignoresSiblingOrder&#9;&#9;= true &#9;&#9;&#9;&#9;myView.showsFPS&#9;&#9;&#9;&#9;&#9;&#9;&#9; = true &#9;&#9;&#9;&#9;myView.showsNodeCount&#9;&#9;&#9;&#9; = true &#9;&#9;&#9;&#9;myView.showsPhysics&#9;&#9;&#9;&#9;&#9; = true &#9;&#9;} &#9;&#9;override func viewWillLayoutSubviews() { &#9;&#9;&#9;&#9;super.viewWillLayoutSubviews() &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GVC viewWillLayoutSubviews") &#9;&#9;&#9;&#9;#endif &#9;&#9;} &#9;&#9; func viewDidAppear() { &#9;&#9;&#9;&#9;super.viewDidAppear(true) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GVC viewDidAppear") &#9;&#9;&#9;&#9;#endif &#9;&#9;} &#9;&#9;override func viewDidLayoutSubviews() { &#9;&#9;&#9;&#9;super.viewDidLayoutSubviews() &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GVC viewDidLayoutSubviews START") &#9;&#9;&#9;&#9;#endif &#9;&#9;&#9;&#9;... get the view.frame &#9;&#9;&#9;&#9;... record some properties in my global variables&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; ... launch GameScene here &#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;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GVC viewDidLayoutSubviews END") &#9;&#9;&#9;&#9;#endif&#9;&#9;&#9;&#9; &#9;&#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;} } GameScene class GameScene: SKScene, SKPhysicsContactDelegate { &#9;&#9;override func sceneDidLoad(){ &#9;&#9;&#9;&#9;super.sceneDidLoad() &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC sceneDidLoad") &#9;&#9;&#9;&#9;#endif &#9;&#9;} &#9;&#9; &#9;&#9;override func didMove(to view: SKView){ &#9;&#9;&#9;&#9;super.didMove(to: view) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC didMove START") &#9;&#9;&#9;&#9;#endif &#9;&#9;&#9;&#9;... load background image &#9;&#9;&#9;&#9;physicsWorld.contactDelegate = self &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;... create just one SKSpriteNode &#9;&#9;&#9;&#9;createGems(myGemRef: &myGems) &#9;&#9;&#9;&#9;#if DEBUG &#9;&#9;&#9;&#9;&#9;&#9;print ("GC didMove END") &#9;&#9;&#9;&#9;#endif &#9;&#9;} } GVC viewDidLoad GVC viewWillLayoutSubviews GVC viewDidLayoutSubviews START GC sceneDidLoad GC didMove START SKNode create SKSPriteNode start SKNode create SKSPriteNode end GC didMove END GVC viewDidLayoutSubviews END
5
0
831
Nov ’20
Having problems subclassing an CGpath as an SKShape
I am trying to create four walls, that would surround the screen. From GameScene I call let leftWall  = MyEdge(side: Walls.left) The code below works. But then I cannot add it as a child to GameScene, also I would like to give it an SKPhysicsBody. My problem is figuring out the super.init. I've tried super.init(texture: nil, color: .clear, size: CGPath(w: 0, h: 0)) super.init() But I always get Type of expression is ambiguous without more context class MyEdge { &#9;&#9;let yourline = SKShapeNode() &#9;&#9;let pathToDraw = CGMutablePath() &#9;&#9;var color : SKColor &#9;&#9;var startAt : CGPoint &#9;&#9;var endAt : CGPoint &#9;&#9;var colMask : UInt32 &#9;&#9;var conMask : UInt32 &#9;&#9;var catMask : UInt32 &#9;&#9;var name : String &#9;&#9;init(side: Walls){ &#9;&#9;&#9;&#9;let whichWall = side &#9;&#9;&#9;&#9;switch whichWall &#9;&#9;&#9;&#9;{ &#9;&#9;&#9;&#9;&#9;&#9;case .left: myGlobalVars.backGround!.size.height+1) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;startAt = CGPoint(x: 5, y: 5) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;endAt = CGPoint(x: 5, y: myGlobalVars.safeSceneRect.size.height-5) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;color = .white &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;colMask = bodyMasks.gemMask.rawValue &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;conMask = bodyMasks.blankMask.rawValue &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;catMask = bodyMasks.edgeMask.rawValue &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;name = "left" &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;pathToDraw.move(to: startAt) &#9;&#9;&#9;&#9;pathToDraw.addLine(to: endAt) &#9;&#9;&#9;&#9;yourline.lineWidth = 2 &#9;&#9;&#9;&#9;yourline.path = pathToDraw &#9;&#9;&#9;&#9;yourline.strokeColor = color &#9;&#9;} }
5
0
437
Nov ’20