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:
Post
Replies
Boosts
Views
Activity
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
}
It turns out that swapping out
yourLine.physicsBody = SKPhysicsBody(edgeLoopFrom: pathToDraw)
for
yourLine.physicsBody = SKPhysicsBody(edgeChainFrom" pathToDraw)
made it work
Not sure why though.
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?
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?
ignore the self.isHidden line. I set that to true false later on.
Sorry, I wanted the NOT (!) equivalent to : if let twinkling = getHighGem() as? MyGem
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.
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.
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.
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.
I cannot access the URL, (after removing the spaces)
Finally got the screenshot up there
http:// 98.7.37.117/screen.gif
I cannot access the URL, (after removing the spaces)
All of a sudden FileZilla won't properly transfer images at all (yes, set to binary). Looking for a new FTP.
Have added super. to all my touches (as seen below) and it still happens
override func touchesMoved(_ touches: SetUITouch, with event: UIEvent?){
super.touchesMoved(touches , with:event)
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
print(touchLocation)
node.position = touchLocation
node.isMoving = true
node.inSlot = false
//addTrailToTwinkle(theNode: node)
}
}
By moving gemBase to the middle, rather than all the way left, the gap between where I touch the screen and how far off to the right the gem is, is less.
So is this because the gems are owned by gemBase? If so not sure why this what the solution is
Nothing. Also, adding libsqlite3.tbd in the Build Phase is not needed.
Every site I visited mentioned the adding that into the Build Phase. So I want to check, is this something that has changed recently with different versions of Xcode?