Post

Replies

Boosts

Views

Activity

Reply to How can I pass a function pointer in Swift?
Thanks for the answer, I will have to study up on Selectors, hate all this different terminology. For instance the syntax: action: action, for: .touchUpInside makes no sense to me. To me, it's still a call back. Will still have to find out how to pass a pointer to a function at some point I guess. Will mark you answer correct, just want to make sure you see this comment p.s. Also confused since the sample code that worked, without having the second action with the comma:
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’21
Reply to What are the SKPhysics settings to make a ball bounce?
How did you define pathToDraw ? I ran the code below four times, once for each edge. func makeLine (pA: CGPoint, pB: CGPoint) -> SKShapeNode { let yourLine = SKShapeNode() let pathToDraw = CGMutablePath() pathToDraw.move(to: pA) pathToDraw.addLine(to: pB) yourLine.lineWidth = 5 yourLine.path = pathToDraw yourLine.isUserInteractionEnabled = false yourLine.strokeColor = .clear yourLine.isHidden = false yourLine.zPosition = 1 yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw) yourLine.physicsBody?.affectedByGravity = false yourLine.physicsBody?.isDynamic = false yourLine.physicsBody?.pinned = true yourLine.physicsBody?.categoryBitMask = bodyMasks.edgeMask.rawValue yourLine.physicsBody?.collisionBitMask = bodyMasks.ballMask.rawValue yourLine.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue return yourLine }
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’21
Reply to How to refine the shape of an SKSpriteNode for tap gestures?
Hence, it will not react to tap outside the shape. While SKPhysicsBody(texture: sprite.texture!, CGSize) does create the physics shape, UITapGestureRecognizer is not affected by it. It sees the tap in the rectangle/square area. Nevertheless, I find that for simple shape as diamond, the test I proposed is really simple. But what happens when I am doing a more complex SKSpriteNode? Is this the way Swift handles this?
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to How can I access an array in one of my classes?
I cannot access the screenshot. I wish I knew what was up with my server, sorry myGV is a structure to hold a few global variables. myGV.guessBar = GuessBar : SKSpriteNode The GuessBar has 6 children, GuessSlot : SKSpriteNode. GuessBar has an array that has all six instances of them. Here is the code for GuessBar: class GuessBar : SKSpriteNode{     var guessSlots : [GuessSlot] = []     init(color: SKColor, size: CGSize) {        super.init(texture: nil, color: color, size: size)     }     required init?(coder aDecoder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }  } Here is the code where I fill the arrays in the guessBar func createGuessBar(color: SKColor, size: CGSize, factor: Int) -> GuessBar {     let myGuessBar = GuessBar(color : color, size: size) //other unrelated code     for x in 0...5{         let mGuessSlot = GuessSlot(color: .clear, size: CGSize(width: iFactor, height: rFactor), width: myGuessBar.size.width,  iFactor: x, guessBarRef: myGuessBar)         myGuessBar.guessSlots.append(mGuessSlot)     } //other unrelated code     return myGuessBar } So the exact info from the debugger reads: myGV.guessBar = (SKSpriteNode?) 0x0000600001984580 *SpriteKit.SKSpriteNode (SKSpriteNode) *guessSlots ([GuessAgain.GuessSlot]) 6 values myGV.guessBar.guessSlots = Invalid Expression The way I see it, everything is running fine. If I expand the guessSlots in the debugger it lists each value. I just can't get the syntax right, going by the last line in the debugger, to access that array from my main structure myGV.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Having strange trouble with touchesMoved, need help.
I got the answer over at Stack overflow, https://stackoverflow.com/questions/67511055/having-a-strange-trouble-with-touchesmoved-position-doesnt-match-location-wher?noredirect=1#comment119406263_67511055 Someone took the time to recreate my issue and had me change: let touchLocation = touch.location(in: self)  to let touchLocation = touch.location(in: gemBase) Of course that leads me to another question, but I'll start another thread for that.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Having strange trouble with touchesMoved, need help.
In which class is this ? ie, what is self ? GameScene toggleHigh, line 10, isMoving That's misc, and a copy error. All the other code be removed and it's the same thing what is the result of the print ? Is it what you expect ? No it's not, that's the problem. So if I move the gemBase, which is its own class) to the right by let's say 100. Then the print result is 100 more than where I'm touching on the screen. That's why I wondered this is due to the gem being owned by the gemBase.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to How can I use a custom image for a Swift button but still control the text separately?
It works now with me only setting the background image. But can I leave setIamge blank? Or do I have to set it to nil?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to How can I use a custom image for a Swift button but still control the text separately?
So I modified the code as such: //    button.setImage(scaledImage, for: .normal)     button.setBackgroundImage(scaledImage, for: .normal) And that does work. But am unsure if I have to do anything with the .setImage method
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to How can I pass a function pointer in Swift?
Thanks for the answer, I will have to study up on Selectors, hate all this different terminology. For instance the syntax: action: action, for: .touchUpInside makes no sense to me. To me, it's still a call back. Will still have to find out how to pass a pointer to a function at some point I guess. Will mark you answer correct, just want to make sure you see this comment p.s. Also confused since the sample code that worked, without having the second action with the comma:
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to What are the SKPhysics settings to make a ball bounce?
So to make sure I understand...from your posts and my playing around with the code, it doesn't matter where the higher restitution is? i.e. ball, edge, block And their restitutions doesn't combine, the software just used the higher one? i.e. ball.restitution = 0.8 block.restitution = 0.4 restitution used by physics engine will be 0.8
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to What are the SKPhysics settings to make a ball bounce?
How did you define pathToDraw ? I ran the code below four times, once for each edge. func makeLine (pA: CGPoint, pB: CGPoint) -> SKShapeNode { let yourLine = SKShapeNode() let pathToDraw = CGMutablePath() pathToDraw.move(to: pA) pathToDraw.addLine(to: pB) yourLine.lineWidth = 5 yourLine.path = pathToDraw yourLine.isUserInteractionEnabled = false yourLine.strokeColor = .clear yourLine.isHidden = false yourLine.zPosition = 1 yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw) yourLine.physicsBody?.affectedByGravity = false yourLine.physicsBody?.isDynamic = false yourLine.physicsBody?.pinned = true yourLine.physicsBody?.categoryBitMask = bodyMasks.edgeMask.rawValue yourLine.physicsBody?.collisionBitMask = bodyMasks.ballMask.rawValue yourLine.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue return yourLine }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to What are the SKPhysics settings to make a ball bounce?
It turns out that swapping out yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw) for yourLine.physicsBody = SKPhysicsBody(edgeChainFrom" pathToDraw) made it work Not sure why though.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to How to refine the shape of an SKSpriteNode for tap gestures?
Hence, it will not react to tap outside the shape. While SKPhysicsBody(texture: sprite.texture!, CGSize) does create the physics shape, UITapGestureRecognizer is not affected by it. It sees the tap in the rectangle/square area. Nevertheless, I find that for simple shape as diamond, the test I proposed is really simple. But what happens when I am doing a more complex SKSpriteNode? Is this the way Swift handles this?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’21
Reply to How to refine the shape of an SKSpriteNode for tap gestures?
Surely it can't view every Node as a rectangle or square? What do you mean ? I mean when you create a spritenode from an image that the node’s area becomes a uniform area that goes beyond the image. ie, look at the orange diamond. Why does the white area (which I drew in for this post) become part of the area the spritenode is part of?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’21
Reply to How to refine the shape of an SKSpriteNode for tap gestures?
ignore the self.isHidden line. I set that to true false later on.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’21
Reply to What is the syntax for "if not" in Swift?
Sorry, I wanted the NOT (!) equivalent to : if let twinkling = getHighGem() as? MyGem
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to How can I access an array in one of my classes?
All my fault. It's right there in the debugger too. My SKSpriteNode should be declared as the subclass, not an SKSpriteNode. That's why I can't access the array. The array exists in my subclass.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to How can I access an array in one of my classes?
I cannot access the screenshot. I wish I knew what was up with my server, sorry myGV is a structure to hold a few global variables. myGV.guessBar = GuessBar : SKSpriteNode The GuessBar has 6 children, GuessSlot : SKSpriteNode. GuessBar has an array that has all six instances of them. Here is the code for GuessBar: class GuessBar : SKSpriteNode{     var guessSlots : [GuessSlot] = []     init(color: SKColor, size: CGSize) {        super.init(texture: nil, color: color, size: size)     }     required init?(coder aDecoder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }  } Here is the code where I fill the arrays in the guessBar func createGuessBar(color: SKColor, size: CGSize, factor: Int) -> GuessBar {     let myGuessBar = GuessBar(color : color, size: size) //other unrelated code     for x in 0...5{         let mGuessSlot = GuessSlot(color: .clear, size: CGSize(width: iFactor, height: rFactor), width: myGuessBar.size.width,  iFactor: x, guessBarRef: myGuessBar)         myGuessBar.guessSlots.append(mGuessSlot)     } //other unrelated code     return myGuessBar } So the exact info from the debugger reads: myGV.guessBar = (SKSpriteNode?) 0x0000600001984580 *SpriteKit.SKSpriteNode (SKSpriteNode) *guessSlots ([GuessAgain.GuessSlot]) 6 values myGV.guessBar.guessSlots = Invalid Expression The way I see it, everything is running fine. If I expand the guessSlots in the debugger it lists each value. I just can't get the syntax right, going by the last line in the debugger, to access that array from my main structure myGV.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Having strange trouble with touchesMoved, need help.
I got the answer over at Stack overflow, https://stackoverflow.com/questions/67511055/having-a-strange-trouble-with-touchesmoved-position-doesnt-match-location-wher?noredirect=1#comment119406263_67511055 Someone took the time to recreate my issue and had me change: let touchLocation = touch.location(in: self)  to let touchLocation = touch.location(in: gemBase) Of course that leads me to another question, but I'll start another thread for that.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Having strange trouble with touchesMoved, need help.
I cannot access the URL, (after removing the spaces) Finally got the screenshot up there http:// 98.7.37.117/screen.gif
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Having strange trouble with touchesMoved, need help.
In which class is this ? ie, what is self ? GameScene toggleHigh, line 10, isMoving That's misc, and a copy error. All the other code be removed and it's the same thing what is the result of the print ? Is it what you expect ? No it's not, that's the problem. So if I move the gemBase, which is its own class) to the right by let's say 100. Then the print result is 100 more than where I'm touching on the screen. That's why I wondered this is due to the gem being owned by the gemBase.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21