I am trying to place a border on top of a white block.
When I set the border's Y positioning only based on the height of the block, I get what I expected: The border is half into the block. Screenshot, top half
The next logical step:
I adjust the border's Y position to include half of its own height. What I expect is the bar resting on top of the block. But for some reason, the border is way above the block. Screenshot, bottom half
Am I somehow confusing pixels for points?
When I do take the border's height into account, I use this line:
My code for the border,
Print out of sizes and positions
a link to the two screen shots
Here is the output for both runs, same order as the image
When I set the border's Y positioning only based on the height of the block, I get what I expected: The border is half into the block. Screenshot, top half
The next logical step:
I adjust the border's Y position to include half of its own height. What I expect is the bar resting on top of the block. But for some reason, the border is way above the block. Screenshot, bottom half
Am I somehow confusing pixels for points?
When I do take the border's height into account, I use this line:
Below in order:self.position = CGPoint(x: myGV.safeSceneRect.width/2, y: myGV.gemBaseSize.height + (self.size.height/2))
My code for the border,
Print out of sizes and positions
a link to the two screen shots
Code Block 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") } }
Here is the output for both runs, same order as the image
> Screen Size (0.0, 44.0, 375.0, 734.0)
Block Size (300.0, 146.8)
Border Size (375.0, 51.380001068115234)
Border Pos (187.5, 146.8000030517578)
www .warptv.com/links/screens.pngScreen Size (0.0, 44.0, 375.0, 734.0)
Block Size (300.0, 146.8)
Block Size (375.0, 51.380001068115234)
Border Pos (187.5, 172.49000549316406)