While placing an SKSpriteNode (bar) on top another SKNode(base), it comes out as it should. Half of it lies on top of the base, the the other within. The code for this is:
self.position = CGPoint(x: self.size.width/2, y: myGV.gemBaseSize.height )
The outcome makes sense since the anchorpoint of the bar is 0.5 0.5.
When I take the anchorpoint into account, the bar ends up way above the base.
self.position = CGPoint(x: self.size.width/2, y: myGV.gemBaseSize.height + (self.size.height/2))
Below is an image that shows the first and second attempts, and below that the full code for the bar" ... only the self.position line is changed in the code. You may have to zoom in, but the lower left picture shows that the bar is half into and half on the base.
If someone has any idea of what's going on, I could really use some help.
Just in case, the entire code for the bar is here:
import Foundation
import SpriteKit
class MyBorder : SKSpriteNode{
var nodeType = NodeType.border
init(){
//create SKSpriteNode, size it based on screen size
super.init(texture: SKTexture(imageNamed: "border"), color: .clear, size: CGSize(width: myGV.safeSceneRect.width, height: myGV.safeSceneRect.height * 0.07))
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.isHidden = true
self.isUserInteractionEnabled = false
self.zPosition = theZ.border
self.alpha = 0.5
// position border on top of block
self.position = CGPoint(x: myGV.safeSceneRect.width/2, y: myGV.blockBaseSize.height)
print("Screen Size \(myGV.safeSceneRect)")
print(“Block Size \(myGV.blockBaseSize)")
print("Border Size \(self.size)")
print("Border Pos \(self.position)")
myGV.gameScene!.addChild(self)
self.isHidden = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}