Post

Replies

Boosts

Views

Activity

What happens if I execute an SKAction run sequence on a node that is already executing another sequence?
I have an SKSpriteNode with an SKAction being run on it: theGem!.run(premAction, completion: {theGem!.run(repeatAction)}) Can't seem to find out the proper steps to run another action, such as: theGem.run(endsequence, completion: {theGem.removeAllActions(); theGem.run(stopAction)}) Should I stop the previous action first? Is there a way to turn the repeat part off so that the first SKAction ends smoothly?
0
0
488
Aug ’21
How to keep two SKPhysicsBodyies from passing through each other?
In my app, I have greyBars and one border bar. The border bar keeps the greyBars from falling off the screen. Only one greyBar is used at a time. When it is completely filed with colored gems, a new bar is created and brought up from the bottom of the screen, with the code below. The result I want is that the new bar, the one with all white diamonds pushes up the old bar and the new bar remains on the bottom. You can see by the screenshot that somehow the new bar ended up on top, even though it was coming from the bottom. I slowed down the duration of the greyBar's movement to see what was going wrong. While the two greyBars do clash with each other, the new one (the one on the bottom) ends up pushing THROUGH the top bar. My assumption was that the new greyBar would just push up the old bar(s), and remain on the bottom. Is there some "solidity" type property that I am missing? myGreyBar[0].physicsBody?.categoryBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].isHidden = false; myGV.gameScene?.addChild(myGreyBar[0]) let moveAction = SKAction.move(to: CGPoint(x:(myGV.safeSceneRect.width/2) - (size.width/2), y: (myGemBase?.size.height)! + (myGV.border?.size.height)! + 200), duration: 10.0) myGreyBar[0].run(moveAction, completion:{myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.borderMask.rawValue|bodyMasks.greyBarMask.rawValue})
0
0
436
Sep ’21
What is the proper term for create a world in Swift?
I know it's uncool to ask vague questions here, but what do they call it when you create a world and follow it with a camera in Swift? Like an RPG? Like Doom? I want to try and learn that now. And more importantly can it be done without using the Xcode scene builder? Can it be done all via code? Thanks, as always. Without the forum I would never have gotten much farther than "Hello World!"
1
0
636
Sep ’21
How can I change the bounce of SKSpriteNode dynamically?
I have a very simple app. All SKSpriteNodes, myBall, myBlue, and myRed. Only myBall moves, affected by gravity, and bounces off of different objects (myRed and myBlue). What I can't figure out is how to make myBall bounce harder or softer depending on which body it hits? I hav been playing with the density of all the objects, but it doesn't seem to make any difference? Is there some property I am unaware of? Or are there other methods?
0
0
392
Oct ’21
How can I pass a function pointer in Swift?
I would like to take this sample code override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50)) button.backgroundColor = .greenColor() button.setTitle("Test Button", forState: .Normal) button.addTarget(self, action: #selector(buttonAction), forControlEvents: .TouchUpInside) self.view.addSubview(button) } func buttonAction(sender: UIButton!) { print("Button tapped") } ...and place the code to create the button in another file. So it would look more like this: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() makeButton(vControl: self) } @objc func buttonAction(sender: UIButton!) { print("Button tapped") } } Of course the main flaw is that I would have to pass a pointer to the function buttonAction. Something like we do in C makeButton(vControl: self, bFunc: &buttonAction) Have Googled a lot but can't seem to find the way to do this. How do I set up the makeButton page to recieve this? func makeButton (vControl: ViewController, bFunc: ???) What would the ??? be in reality? thanks
3
0
1k
Oct ’21
What are the SKPhysics settings to make a ball bounce?
I've created a ball, and boxed my game scene. The balls physics settings are: self.physicsBody!.affectedByGravity = true self.physicsBody!.restitution = 1.0 self.physicsBody!.linearDamping = 0 self.physicsBody!.friction = 0.3 self.physicsBody!.isDynamic = true self.physicsBody!.mass = 0.5 self.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue self.physicsBody?.collisionBitMask  = bodyMasks.edgeMask.rawValue self.physicsBody?.categoryBitMask   = bodyMasks.ballMask.rawValue When I box the game scene with: self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame) the ball bounces back up as intended. However, if I replace edgeLoopFrom with my own custom borders: yourLine.lineWidth = 5 yourLine.path = pathToDraw yourLine.isUserInteractionEnabled = false yourLine.strokeColor = .clear yourLine.isHidden = false yourLine.zPosition = 10 yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw) yourLine.physicsBody?.affectedByGravity = false yourLine.physicsBody?.pinned = true yourLine.physicsBody?.categoryBitMask = bodyMasks.edgeMask.rawValue yourLine.physicsBody?.collisionBitMask = bodyMasks.ballMask.rawValue yourLine.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue the ball just comes down with a thud, stops, and doesn't bounce., So am trying to figure out what physics settings I have to give to my custom made edges so that the ball bounces?
7
0
1.4k
Oct ’21
How can I use a custom image for a Swift button but still control the text separately?
Below is a simple code patch I use to create a custom button, am new at this. I noticed the text does not appear and am wondering what the proper method is for making the text appear? func makeButton (vControl: ViewController, action: Selector) { let myButtonImage = UIImage(named: "Picture1.png") let imageScale = myButtonImage!.size.width / myButtonImage!.size.height let wwidth = vControl.self.view.bounds.width let button = CreateButton(frame: CGRect(x: 100, y: 100, width: (myButtonImage?.size.width)!/3, height: (myButtonImage?.size.height)!/3)) button.setImage(myButtonImage, for: .normal) button.backgroundColor = .clear button.setTitleColor(.black, for: .normal) button.setTitle("Test Button", for: .normal) button.addTarget(vControl, action: action, for: .touchUpInside) vControl.view.addSubview(button) button.center = vControl.view.center }
3
0
2k
Oct ’21
Is Multiple inheritance not allowed in Swift?
So am watching a Speech To Text demo on YouTube, here: https://www.youtube.com/watch?v=SZJ8zjMGUcY There are no files, so am typing from the screen, and immediately run into an error that confuses me. at class ViewController : UIViewController, SFSpeechRecognizer { here's a screenshot: Swift gives me an error indicating that Multiple Inheritance is not allowed. The programmer doesn't have files to download, and I like to start from scratch anyway, typing and copying so I am forced to read each line. Is there something I have to change in the project itself that allows Multiple Inheritances? This video is from last year, and is on Swift 5.0. So I don't think there could be that much of a major change in Swift in that time. Thanks
2
0
2.6k
Nov ’21
Looking for a proper Speech to Text tutorial
So sorry if I should't be asking this here, but am trying to find a current-ish tutorial on how to make an app that converts speech to text in real time. Transcribing from text to speech as you're speaking. I've found a few one's on YouTube, but they are quite old, or just transcribing from a recorded file, etc. etc. If anyone is aware of a good tutorial, paid or not, I would so appreciate any link. Thank you
1
0
778
Nov ’21
How can I apply safeAreaLayouts to multiple views?
When my app starts up I have my ViewController, which automatically creates my MainScreen (also a view controller). Right after self.addChild(mainController) I call a function which sets my constraints func setConstraints (vc: UIViewController) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } All is fine up to this point, the MainScreen is bound by the top and bottom safe areas. At some point from MainScreen I create another UIViewController. countController.modalPresentationStyle = .fullScreen self.present(countController, animated: true, completion: {}) Yet, no matter how hard I try to apply the constraints to the new controller, I crash with the following msg: Unable to activate constraint with anchors <NSLayoutXAxisAnchor....because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal." Am too new to figure out where my error is.
0
0
384
Nov ’21
Is there a way to detect when an SKPhysicsBody stops bouncing?
I was looking to find a way to find out if my SKSpriteNode with an SKPhysicsBody is in motion. I create a box, raise it above the bar, then set the bar and box masks to collide. The bar is pinned, but would love to know when the box stops bouncing.
Replies
2
Boosts
0
Views
574
Activity
Aug ’21
Why do I get touchesCanceled all the time?
Just curious why I get touchesCanceled even after I process: @objc func tappedView(_ sender:UITapGestureRecognizer) It's requiring a lot of extra coding to determine a real cancel vs I just got a tap.
Replies
2
Boosts
0
Views
444
Activity
Aug ’21
Can i turn a touchesCancelled onto touchesEnded?
I handled everything through touchesEnded. Was curious if I could hand off the call to touchesEnded from touchesCancelled?
Replies
2
Boosts
0
Views
449
Activity
Aug ’21
What happens if I execute an SKAction run sequence on a node that is already executing another sequence?
I have an SKSpriteNode with an SKAction being run on it: theGem!.run(premAction, completion: {theGem!.run(repeatAction)}) Can't seem to find out the proper steps to run another action, such as: theGem.run(endsequence, completion: {theGem.removeAllActions(); theGem.run(stopAction)}) Should I stop the previous action first? Is there a way to turn the repeat part off so that the first SKAction ends smoothly?
Replies
0
Boosts
0
Views
488
Activity
Aug ’21
How to keep two SKPhysicsBodyies from passing through each other?
In my app, I have greyBars and one border bar. The border bar keeps the greyBars from falling off the screen. Only one greyBar is used at a time. When it is completely filed with colored gems, a new bar is created and brought up from the bottom of the screen, with the code below. The result I want is that the new bar, the one with all white diamonds pushes up the old bar and the new bar remains on the bottom. You can see by the screenshot that somehow the new bar ended up on top, even though it was coming from the bottom. I slowed down the duration of the greyBar's movement to see what was going wrong. While the two greyBars do clash with each other, the new one (the one on the bottom) ends up pushing THROUGH the top bar. My assumption was that the new greyBar would just push up the old bar(s), and remain on the bottom. Is there some "solidity" type property that I am missing? myGreyBar[0].physicsBody?.categoryBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].isHidden = false; myGV.gameScene?.addChild(myGreyBar[0]) let moveAction = SKAction.move(to: CGPoint(x:(myGV.safeSceneRect.width/2) - (size.width/2), y: (myGemBase?.size.height)! + (myGV.border?.size.height)! + 200), duration: 10.0) myGreyBar[0].run(moveAction, completion:{myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.borderMask.rawValue|bodyMasks.greyBarMask.rawValue})
Replies
0
Boosts
0
Views
436
Activity
Sep ’21
What is the proper term for create a world in Swift?
I know it's uncool to ask vague questions here, but what do they call it when you create a world and follow it with a camera in Swift? Like an RPG? Like Doom? I want to try and learn that now. And more importantly can it be done without using the Xcode scene builder? Can it be done all via code? Thanks, as always. Without the forum I would never have gotten much farther than "Hello World!"
Replies
1
Boosts
0
Views
636
Activity
Sep ’21
How can I give an SkSpriteNode an initial push?
I have an SkSpriteNode (ball) in a box. Gravity is set to false, otherwise it has an SkPhysicsBody to bounce off of walls. Is there a method to give the ”ball” an initial push in a specified direction and velocity/strength wise?
Replies
1
Boosts
0
Views
444
Activity
Oct ’21
How can I change the bounce of SKSpriteNode dynamically?
I have a very simple app. All SKSpriteNodes, myBall, myBlue, and myRed. Only myBall moves, affected by gravity, and bounces off of different objects (myRed and myBlue). What I can't figure out is how to make myBall bounce harder or softer depending on which body it hits? I hav been playing with the density of all the objects, but it doesn't seem to make any difference? Is there some property I am unaware of? Or are there other methods?
Replies
0
Boosts
0
Views
392
Activity
Oct ’21
How can I pass a function pointer in Swift?
I would like to take this sample code override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50)) button.backgroundColor = .greenColor() button.setTitle("Test Button", forState: .Normal) button.addTarget(self, action: #selector(buttonAction), forControlEvents: .TouchUpInside) self.view.addSubview(button) } func buttonAction(sender: UIButton!) { print("Button tapped") } ...and place the code to create the button in another file. So it would look more like this: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() makeButton(vControl: self) } @objc func buttonAction(sender: UIButton!) { print("Button tapped") } } Of course the main flaw is that I would have to pass a pointer to the function buttonAction. Something like we do in C makeButton(vControl: self, bFunc: &buttonAction) Have Googled a lot but can't seem to find the way to do this. How do I set up the makeButton page to recieve this? func makeButton (vControl: ViewController, bFunc: ???) What would the ??? be in reality? thanks
Replies
3
Boosts
0
Views
1k
Activity
Oct ’21
What are the SKPhysics settings to make a ball bounce?
I've created a ball, and boxed my game scene. The balls physics settings are: self.physicsBody!.affectedByGravity = true self.physicsBody!.restitution = 1.0 self.physicsBody!.linearDamping = 0 self.physicsBody!.friction = 0.3 self.physicsBody!.isDynamic = true self.physicsBody!.mass = 0.5 self.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue self.physicsBody?.collisionBitMask  = bodyMasks.edgeMask.rawValue self.physicsBody?.categoryBitMask   = bodyMasks.ballMask.rawValue When I box the game scene with: self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame) the ball bounces back up as intended. However, if I replace edgeLoopFrom with my own custom borders: yourLine.lineWidth = 5 yourLine.path = pathToDraw yourLine.isUserInteractionEnabled = false yourLine.strokeColor = .clear yourLine.isHidden = false yourLine.zPosition = 10 yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw) yourLine.physicsBody?.affectedByGravity = false yourLine.physicsBody?.pinned = true yourLine.physicsBody?.categoryBitMask = bodyMasks.edgeMask.rawValue yourLine.physicsBody?.collisionBitMask = bodyMasks.ballMask.rawValue yourLine.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue the ball just comes down with a thud, stops, and doesn't bounce., So am trying to figure out what physics settings I have to give to my custom made edges so that the ball bounces?
Replies
7
Boosts
0
Views
1.4k
Activity
Oct ’21
How can I use a custom image for a Swift button but still control the text separately?
Below is a simple code patch I use to create a custom button, am new at this. I noticed the text does not appear and am wondering what the proper method is for making the text appear? func makeButton (vControl: ViewController, action: Selector) { let myButtonImage = UIImage(named: "Picture1.png") let imageScale = myButtonImage!.size.width / myButtonImage!.size.height let wwidth = vControl.self.view.bounds.width let button = CreateButton(frame: CGRect(x: 100, y: 100, width: (myButtonImage?.size.width)!/3, height: (myButtonImage?.size.height)!/3)) button.setImage(myButtonImage, for: .normal) button.backgroundColor = .clear button.setTitleColor(.black, for: .normal) button.setTitle("Test Button", for: .normal) button.addTarget(vControl, action: action, for: .touchUpInside) vControl.view.addSubview(button) button.center = vControl.view.center }
Replies
3
Boosts
0
Views
2k
Activity
Oct ’21
Unable to update to Xcode 13.1 storage wise
While I do need to get another HD, I currently have 34.85 GB (12.61 GB purgeable) available. Yet for some reason when I try to run update on Xcode, it says I don't have enough HD space. That's three times the final size of the new Xcode. Is there some way around this?
Replies
1
Boosts
0
Views
1.7k
Activity
Oct ’21
Is Multiple inheritance not allowed in Swift?
So am watching a Speech To Text demo on YouTube, here: https://www.youtube.com/watch?v=SZJ8zjMGUcY There are no files, so am typing from the screen, and immediately run into an error that confuses me. at class ViewController : UIViewController, SFSpeechRecognizer { here's a screenshot: Swift gives me an error indicating that Multiple Inheritance is not allowed. The programmer doesn't have files to download, and I like to start from scratch anyway, typing and copying so I am forced to read each line. Is there something I have to change in the project itself that allows Multiple Inheritances? This video is from last year, and is on Swift 5.0. So I don't think there could be that much of a major change in Swift in that time. Thanks
Replies
2
Boosts
0
Views
2.6k
Activity
Nov ’21
Looking for a proper Speech to Text tutorial
So sorry if I should't be asking this here, but am trying to find a current-ish tutorial on how to make an app that converts speech to text in real time. Transcribing from text to speech as you're speaking. I've found a few one's on YouTube, but they are quite old, or just transcribing from a recorded file, etc. etc. If anyone is aware of a good tutorial, paid or not, I would so appreciate any link. Thank you
Replies
1
Boosts
0
Views
778
Activity
Nov ’21
How can I apply safeAreaLayouts to multiple views?
When my app starts up I have my ViewController, which automatically creates my MainScreen (also a view controller). Right after self.addChild(mainController) I call a function which sets my constraints func setConstraints (vc: UIViewController) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } All is fine up to this point, the MainScreen is bound by the top and bottom safe areas. At some point from MainScreen I create another UIViewController. countController.modalPresentationStyle = .fullScreen self.present(countController, animated: true, completion: {}) Yet, no matter how hard I try to apply the constraints to the new controller, I crash with the following msg: Unable to activate constraint with anchors <NSLayoutXAxisAnchor....because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal." Am too new to figure out where my error is.
Replies
0
Boosts
0
Views
384
Activity
Nov ’21