Post

Replies

Boosts

Views

Activity

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 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 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 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 Why does a dismissed child UIView doesn't reappear properly after its first appearance?
Experimenting around I found that if I didn't set the child's constraints (see below), then it would always work. Is there a method to remove the constraints of a UIView before deleting it? vc is the Child UIView and pc is its parent func setConstraints (vc: UIViewController, pc: UIView) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’21