Post

Replies

Boosts

Views

Activity

How to refine the shape of an SKSpriteNode for tap gestures?
In my app I create mutiple SKSpriteNodes, gems. Code snippet 1 When I loop through nodes from the main scene in a tap gesture, Code snippet 2, the gems register in a perfect square shape even though they are not. I have highlighted all areas that the orange gem registers in a tap as white. Here is the screen shot http://98.7.37.117/gem.png Since the gem is itself not a square, I'd like to know if there is a way refine its shape so it would only show up in the list of nodes in UITapGestureRecognizer if the orange part is tapped. I have even tried by assigning it a physicsBody. But that made no difference. Code Snippet 1 class MyGem : SKSpriteNode{ init(iColor : Gems) { fileName = "\(iColor)_gem" let skTexture = SKTexture(imageNamed: fileName) super.init(texture: skTexture, color: .clear, size: .zero) self.isHidden = true self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.size = CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height) self.zPosition = theZ.gem self.position = CGPoint(x: 0, y: 0 ) self.isUserInteractionEnabled = false self.name = "gem" } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Code Snippet 2 @objc func tappedView(_ sender:UITapGestureRecognizer) { if sender.state == .ended{ var post = sender.location(in: sender.view) post = self.convertPoint(fromView: post) for node in self.nodes(at: post){ if let touchNode = node as? MyGem print("touched gem") highliteGem(theGem: touchNode, clearAll: false) return }
6
0
927
Jul ’21
What is the syntax for "if not" in Swift?
I have the code below which works just fine. getTwinklingGem returns type MyGem. What I cannot figure out is if there is a proper syntax for writing the NOT into the if statement. Am still too new to Swift. This works, but seems lengthy: if let twinkling = getHighGem(), twinkling != nil Is this the proper way to test for a nil return? if let twinkling = getHighGem() as? MyGem if let twinkling = getTwinklingGem() { print ("not nil") }
4
0
2.5k
Jun ’21
How can I return a nil in Swift
I have a subclass of SKSpriteNode called MyGem. There are multiple instances of this class at runtime. They are all in an array of MyGems. At a specific point I would like to find out which MyGem is twinkling. The problem I am running into is if no MyGem is twinkling. What do I return? I can't return a nil. 'nil' is incompatible with return type 'MyGem' So what do I return? I thought of returning the index number of the MyGem in the array class, and then passing -1 if none were twinkling. But that seems kludgy. func getHighGem() -> MyGem {    for gem in myGems {     if gem.twinkling == true {     return gem       }    }     return nil //this line causes the IDE error }
1
0
3.7k
Jun ’21
Is there a way to translate touches to screen coordinates
As you can see in the last two lines of the code below, I specify a specific SKSpriteNode to get the correct (or is it, adjusted?) touch coordinates. The last line is just left in there to compare while I am debugging. I was curious if there was already a method in Swift that translates any coordinates handed to it into physical screen coordinates? It would just be easier than having to first find out: Is this item that I am tracking, owned by the main GameScene, or a SKSpriteNode that has been placed somewhere other than 0,0 on the GameScene? override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {         super.touchesEnded(touches , with:event)         var delta = CGPoint(x: 0, y: 0)         guard touches.first != nil else { return }         if let touch = touches.first,            let node = myGV.currentGem,            node.isMoving == true {             let touchLocation = touch.location(in: myGV.guessBar!)             let touchLocation2 = touch.location(in: self)
1
0
838
Jun ’21
How can I access an array in one of my classes?
myGV is a structure where I store a handful of global variables. The following are all sub-classes of SKSpriteNode: I have a class called guessingBar which holds 6 guessSlots. The former class has an array of the guessSlots for me to loop through. I just don't know the syntax of how to access the array. myGV holds multiple variables, so the SKSpriteNode guessBar can be found at: myGV.guessBar I expected to be able to read the array with: myGV.guessBar.guessSlots[x] but as you can see from the debugger screenshot, I cannot. In the screenshot you can see that everything is initialized. Am I missing some silly typo, or is the syntax escaping me? http: //98.7.37.117/s.png
3
0
633
Jun ’21
Having strange trouble with touchesMoved, need help.
Am trying to make a game, where I drag gems around. The hierarchy is: GameScene (this is the view controller) gemBase, which holds the gems (light grey) SKSpriteNode gems SKSpriteNode The gems are children of gemBase, which is a child of GameScene. When the gemBase is at 0,0 everything works fine when I drag the gems. They are in the same place I am touching the screen. But I want to offer a left-handed feature, where I offset the gemBase to the rightsize of the screen. All gems automatically move with the base so I don't need to recalculate their positions. But then, when I try to move the gems, they are offset to the right of where I am touching the screen. They are offset by as much as I move the gemBase. Below is my only code where I handle touchesMoved (in GameScene) If you're having problems visualizing what I am describing, the screen shot is at: http: // 98.7.37.117/ss.gif Do I have to convert the touch.location?     override func touchesMoved(_ touches: SetUITouch, with event: UIEvent?){         guard touches.first != nil else { return }         if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}         if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {             let touchLocation = touch.location(in: self)             node.moved    = true             node.position = touchLocation             node.isMoving = true             node.inSlot = false             //addTrailToTwinkle(theNode: node)         }     }
8
0
902
May ’21
Need help on SQLite wrapper for Swift
I am using the SQLite wrapper for Xcode. I got it from the link below and did install it. But was hoping there would better documentation, or tutorials out there for it. Am new enough at Swift and its syntax. Whatever can make this easier for me would be a big help. https: //git.pado.name/reviewspur/ios/tree/fd2486cf91e422e2df8d048ffd2d40ea89527685/Carthage/Checkouts/SQLite.swift/Documentation#building-type-safe-sql
0
0
408
May ’21
How to refine the shape of an SKSpriteNode for tap gestures?
In my app I create mutiple SKSpriteNodes, gems. Code snippet 1 When I loop through nodes from the main scene in a tap gesture, Code snippet 2, the gems register in a perfect square shape even though they are not. I have highlighted all areas that the orange gem registers in a tap as white. Here is the screen shot http://98.7.37.117/gem.png Since the gem is itself not a square, I'd like to know if there is a way refine its shape so it would only show up in the list of nodes in UITapGestureRecognizer if the orange part is tapped. I have even tried by assigning it a physicsBody. But that made no difference. Code Snippet 1 class MyGem : SKSpriteNode{ init(iColor : Gems) { fileName = "\(iColor)_gem" let skTexture = SKTexture(imageNamed: fileName) super.init(texture: skTexture, color: .clear, size: .zero) self.isHidden = true self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.size = CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height) self.zPosition = theZ.gem self.position = CGPoint(x: 0, y: 0 ) self.isUserInteractionEnabled = false self.name = "gem" } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Code Snippet 2 @objc func tappedView(_ sender:UITapGestureRecognizer) { if sender.state == .ended{ var post = sender.location(in: sender.view) post = self.convertPoint(fromView: post) for node in self.nodes(at: post){ if let touchNode = node as? MyGem print("touched gem") highliteGem(theGem: touchNode, clearAll: false) return }
Replies
6
Boosts
0
Views
927
Activity
Jul ’21
What is the syntax for "if not" in Swift?
I have the code below which works just fine. getTwinklingGem returns type MyGem. What I cannot figure out is if there is a proper syntax for writing the NOT into the if statement. Am still too new to Swift. This works, but seems lengthy: if let twinkling = getHighGem(), twinkling != nil Is this the proper way to test for a nil return? if let twinkling = getHighGem() as? MyGem if let twinkling = getTwinklingGem() { print ("not nil") }
Replies
4
Boosts
0
Views
2.5k
Activity
Jun ’21
How can I return a nil in Swift
I have a subclass of SKSpriteNode called MyGem. There are multiple instances of this class at runtime. They are all in an array of MyGems. At a specific point I would like to find out which MyGem is twinkling. The problem I am running into is if no MyGem is twinkling. What do I return? I can't return a nil. 'nil' is incompatible with return type 'MyGem' So what do I return? I thought of returning the index number of the MyGem in the array class, and then passing -1 if none were twinkling. But that seems kludgy. func getHighGem() -> MyGem {    for gem in myGems {     if gem.twinkling == true {     return gem       }    }     return nil //this line causes the IDE error }
Replies
1
Boosts
0
Views
3.7k
Activity
Jun ’21
Is there a way to translate touches to screen coordinates
As you can see in the last two lines of the code below, I specify a specific SKSpriteNode to get the correct (or is it, adjusted?) touch coordinates. The last line is just left in there to compare while I am debugging. I was curious if there was already a method in Swift that translates any coordinates handed to it into physical screen coordinates? It would just be easier than having to first find out: Is this item that I am tracking, owned by the main GameScene, or a SKSpriteNode that has been placed somewhere other than 0,0 on the GameScene? override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {         super.touchesEnded(touches , with:event)         var delta = CGPoint(x: 0, y: 0)         guard touches.first != nil else { return }         if let touch = touches.first,            let node = myGV.currentGem,            node.isMoving == true {             let touchLocation = touch.location(in: myGV.guessBar!)             let touchLocation2 = touch.location(in: self)
Replies
1
Boosts
0
Views
838
Activity
Jun ’21
How can I access an array in one of my classes?
myGV is a structure where I store a handful of global variables. The following are all sub-classes of SKSpriteNode: I have a class called guessingBar which holds 6 guessSlots. The former class has an array of the guessSlots for me to loop through. I just don't know the syntax of how to access the array. myGV holds multiple variables, so the SKSpriteNode guessBar can be found at: myGV.guessBar I expected to be able to read the array with: myGV.guessBar.guessSlots[x] but as you can see from the debugger screenshot, I cannot. In the screenshot you can see that everything is initialized. Am I missing some silly typo, or is the syntax escaping me? http: //98.7.37.117/s.png
Replies
3
Boosts
0
Views
633
Activity
Jun ’21
Is there a method that returns how much space is being occupied by two sprites at the same time?
I am working on my first game, and I do know about collision detecting. I am curious if there is a method that returns how much space is being occupied by two sprites at the same time? Am sure there are multiple reasons to calculate this, but in my case one sprite can be touching at least 2 other sprites at once.
Replies
1
Boosts
0
Views
507
Activity
May ’21
Does SKLabelNode have a method to "automatically" adjust font size?
Am adding text to a Game Scene. Since I am new at this, I am curious about different screen sizes? Will a font size of 65 change in relationship to the SKSpriteNode it is a child of? Is there method that detects and sets the proper font size for you, based on the size of its SKSpriteNode parent?
Replies
1
Boosts
0
Views
740
Activity
May ’21
Is it ok to have each SKSPriteNode's isUserInteractionEnabled set to true?
Am making a game which will have 6 interactive SKSpriteNodes. Is there anything wrong with having each node handle its own user interactions? Or is better to have all user touch interactions handled through one scene (GameScene)? Or is there, perhaps, no difference?
Replies
0
Boosts
0
Views
437
Activity
May ’21
Having strange trouble with touchesMoved, need help.
Am trying to make a game, where I drag gems around. The hierarchy is: GameScene (this is the view controller) gemBase, which holds the gems (light grey) SKSpriteNode gems SKSpriteNode The gems are children of gemBase, which is a child of GameScene. When the gemBase is at 0,0 everything works fine when I drag the gems. They are in the same place I am touching the screen. But I want to offer a left-handed feature, where I offset the gemBase to the rightsize of the screen. All gems automatically move with the base so I don't need to recalculate their positions. But then, when I try to move the gems, they are offset to the right of where I am touching the screen. They are offset by as much as I move the gemBase. Below is my only code where I handle touchesMoved (in GameScene) If you're having problems visualizing what I am describing, the screen shot is at: http: // 98.7.37.117/ss.gif Do I have to convert the touch.location?     override func touchesMoved(_ touches: SetUITouch, with event: UIEvent?){         guard touches.first != nil else { return }         if toggleHigh {highliteGem(theGem: myGems[0], clearAll: true)}         if let touch = touches.first, let node = myGV.currentGem, node.isMoving == true {             let touchLocation = touch.location(in: self)             node.moved    = true             node.position = touchLocation             node.isMoving = true             node.inSlot = false             //addTrailToTwinkle(theNode: node)         }     }
Replies
8
Boosts
0
Views
902
Activity
May ’21
Need help on SQLite wrapper for Swift
I am using the SQLite wrapper for Xcode. I got it from the link below and did install it. But was hoping there would better documentation, or tutorials out there for it. Am new enough at Swift and its syntax. Whatever can make this easier for me would be a big help. https: //git.pado.name/reviewspur/ios/tree/fd2486cf91e422e2df8d048ffd2d40ea89527685/Carthage/Checkouts/SQLite.swift/Documentation#building-type-safe-sql
Replies
0
Boosts
0
Views
408
Activity
May ’21
Checking what I need to include SQLite in my Swift apps
My app needs a database and I would like to use SQLite. Other than using import SQLite3 and adding libsqlite3.tbd in the Build Phase Are there any other files I need to copy or import into my project?
Replies
3
Boosts
0
Views
792
Activity
May ’21
How do I allow Xcode to access my local files?
Xcode updated, and when it first asked, allow Xcode to access to local files, I said No by mistake. Now I don't know how to change that? I just keep getting Could not open workspace file at  I can open the project using File-Open-Project. But I can't open from the Start Window.
Replies
1
Boosts
0
Views
1.2k
Activity
May ’21