Post

Replies

Boosts

Views

Activity

Unable to update a passed struct, even tho it's declared as var
I am passing a structure into a method. Everything is defined as var, yet within the method where I am just changing one of it's properties, BackGroundStruct.h = 0.1 I get the following error : Cannot assign to property: 'BackGroundStruct' is a 'let' constant I purposely set everything to var and am unsure as to what is going wrong here. Also please excuse the sloppy variable naming here. /* structure */ struct backGroundStruct {     var w : CGFloat     var h : CGFloat     var bGSprite : SKSpriteNode } /*method*/ func heresJohnny (BackGroundStruct : backGroundStruct) {         BackGroundStruct.h = 0.1 } /* declare backGroundstruct */ var wnh : backGroundStruct /* create background and pass it to struct init*/ var background = SKSpriteNode(imageNamed: "background") background.size = self.size wnh = backGroundStruct.init(w: background.size.width, h: background.size.height, bGSprite: background) /* call method */ pegBaseBoard.heresJohnny(BackGroundStruct : wnh)
3
1
5.2k
Jul ’20
How to use CGSize or CGpoint as values in a method parameter
Yes, very new to Swift. Within a GameScene I'm creating a background and then an SKShapeNode within it. Everything works. So now I have a subclass of the SKShapeNode, and it works for initing the SKShapeNode. So my next my goal is to add a method to position, take care of color, etc. But I just can't figure out how to pass certain items within methods/functions. For instance this is the code I use within GameScene, that works: let background = SKSpriteNode(imageNamed: "background") background.size = self.size background.position = CGPoint(x: self.size.width/2, y: self.size.height/2) background.zPosition = -1 self.addChild(background) 			 pegBase = SKShapeNode(rectOf: CGSize(width: self.size.width * 0.8, height: self.size.height * 0.2)) I just can't seem to figure out how to pass the background.size property. Yes, I could break it down to width and height separately and then pass them to my method, but that sounds kludgy. Would like to do it correctly. Thank you
7
0
3.9k
Jul ’20
Unable to initialized a class that subclasses SKShapeNode, specifically (rectOf: CGSize)
Am trying to subclass SKShapeNode yet it never works. Specifically the SKShapeNode(rectOf: CGSize). Trying to use init(), super.init, and sometimes the compiler tells me to use the designated initializer, which I cannot find to save my life. Am using Xcode 11 and Swift 5. Here is a sample of one of my declaration attempts and my call. The self element in the call is from the background pic. It works if I create an SKShapeNode directly using the same parameters. But would like to subclass this so I can add custom methods and properties. I've scoured the internet and so many other forums. Not one reply. I'm desperate at this point. Thank you p.s. I apologize this is a repost. But I only realized too late that I used the wrong tags. In this sample code I removed all the part that fill color, and position, set the zPosition, etc. because it all works if I do it straight from my GameScene, without using a custom SubClassed attempt. class PegBase : SKShapeNode { init(rectOfPegBase: CGSize) {     super.init()     self.fillColor = SKColor.red     self.strokeColor = SKColor.red self.Position = 0 }   required init?(coder aDecoder: NSCoder) {       fatalError("init(coder:) has not been implemented")    }} let childP = PegBase(rectOfPegBase: CGSize(width: self.size.width * 0.8, height: self.size.height * 0.2)) self.addChild(childP) 
8
0
1.6k
Jul ’20
How to properly make a subclass of SKShapeNode
Am trying to subclass SKShapeNode yet it never appears. I followed it into the debugger and am going through the init method, with the parameters I send in. But obviously I'm doing something wrong. Here is my declaration and my call. The self element in the call is from the background pic. It works if I create an SKShapeNode directly using the same parameters. But would like to subclass this so I can add custom methods and properties: Thank you class PegBase : SKShapeNode { init(rectOfPegBase: CGSize) {     super.init()     self.fillColor = SKColor.red     self.strokeColor = SKColor.red     self.zPosition = 0 		 }   required init?(coder aDecoder: NSCoder) {       fatalError("init(coder:) has not been implemented")     } } let childP = PegBase(rectOfPegBase: CGSize(width: self.size.width * 0.8, height: self.size.height * 0.2))         self.addChild(childP)  
1
0
549
Jul ’20
Trying to pull size info from a SKShapeNode objects
This was a much longer question, which I solved by myself because I realized I wasn't using the height and width of the SKShapeNode, I was using the width and height from the SKSpriteNode to set everything positions. But that leaves me with a question I still can't find the answer to: How to I get the size info from an SKShapeNode object? I do need it to proceed further. Sure I can calculate it as I set its position, but surely that property must be in there already.
0
0
276
Jul ’20
How do I keep my app from stopping Music on iPhone
Still new at this, and I tried Google without results. Finally finished a game tutorial and ready to try my own. However, I noticed that when I run the game built from the YouTube tutorial it shuts off the iPhones music player. Now while the game does use sounds it doesn't used them till way into the game. Yet still at the game startup, the music is cut off. So is there a way to program my game to detect that there's music playing and not use any sound, or a lower sound without shutting off the music player? Thank you
1
0
2.0k
Jul ’20
Can I detect gestures on an UITextView object via the story board editor
I have the code below, copyright Paul Hudson, from one of his lessons online. And it works just fine. But I tried to also capture the tapping gesture through Xcode's IDE ctrl-drag method. That method only allows me to create an IBOutlet connection. I was hoping there was a way to do this through the IDE, just to make things quicker? When I did someone else's lesson online, ctrl-dragging a button (with Asst. Editor) did allow me to add and @IBAction connection. If anyone can tell me if there is something I am missing? Thank you import UIKit class MemoryViewController: UIViewController {     @IBOutlet weak var textView: UITextView!     var item: MemoryItem!     var blankCounter = 0     override func viewDidLoad() {         super.viewDidLoad()         showText() // capture tap gesture from touchscreen             let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(wordsTapped))         textView.addGestureRecognizer(tapRecognizer)  }     func showText()     { // code to fill cell     }     @objc func wordsTapped()     { ....misc code         showText()     } }
4
0
2.9k
Jun ’20
Why won't my background image expand based on orientation or screen size?
Hello, Working on a really simple learning app. Center and align three button, and have a background image fill the entire screen. However when I change the device in View As section (bottom of Xcode) the background does not self adjust for iPads, or horizontal oriantaion, etc.I have the four constraints set to "view and 0"There's no other functionality am practicing makeing a layout screen.All my other buttons and text stay where they are if I change View As to any other device.So I must be missing something.Can someone help me please?Thank you
1
0
3.2k
Jun ’20
iPhone won't connect to Xcode over WiFi
Hello, Just starting to learn Xcode and I can test the first chapter's app on my iPhone if it's conncted via USB-C. The book walks me through the part where I can allow Xcode to connect to the iPhone via WiFi, just checking "Connect via Network."Yet Xcode cannot find my phone unless it's connected via USB. When I go to Devices that checkbox stays checked, unless I unplug the phone it which case that box doesn't even appear.And yes, they are both on the same WiFi, it's the only one I have and it's up and running.Any thoughs?
6
0
19k
May ’20
What are the specs requirement for Mac developing for iPhones, iPads, etc?
Hello,Tried once along time ago, but stopped, to learn to develop for iPhone, iPads, etc. I am a developer, jsut on the PC side. So now that I need to change, what are the mid-level requirments for a Mac (CPU, RAM, Storage specs, OS version wise) to get to start developing for iPhones, iPads, etc? Low-level would be too slow, and this is not the economy for me to plunk down for the top of the line Mac.Sadly, like many people, I have plenty of free time to learn now.Many thanks,
4
0
3.2k
Apr ’20