I am developing a game in which my Locomotive is following a UIBezierPath
that mimics an oval shaped Track.
The math of the following is not "adding up" .. if it is, I am obviously not understanding the math of the layout.
Bottom line = the following code does not display the UIBezierPath
.
Here's the code that creates this UIBezierPath
.. please note the math in the comments:
func createTrainPath() {
trackRect = CGRect(x: 0.0,
y: 0.0 - roomHeight/2 + tracksHeight,
width: tracksWidth,
height: tracksHeight)
// trackRect = (0.0, -207.0, 940.0, 476.0) // portrait
// trackRect = (0.0, -274.0, 470.0, 238.0) // landscape
print("trackRect = \(trackRect!)")
trackPath = UIBezierPath(ovalIn: trackRect)
let theTrackShapeNode = SKShapeNode(path: trackPath.cgPath, centered: true)
theTrackShapeNode.zPosition = 100 // for testing
theTrackShapeNode.position = myTracks.position
theTrackShapeNode.lineWidth = 4.0
theTrackShapeNode.strokeColor = SKColor.blue
if let ourScene = GameScene(fileNamed: "GameScene") {
print("here") // this shows
ourScene.addChild(theTrackShapeNode) // does *not* show?
}
} // createTrainPath
In Portrait mode, the UIScreen
measures 1024 x 1366 and the Track measures 940 x 476 with its top edge down 207 from the center of the UIScreen
.
In Landscape mode, the UIScreen
measures 1366 x 1024 and the Track measures 470 x 238 with its top edge down 274 from the center of the UIScreen
.
In both modes, the bottom edge of the Track is supposed to be flush with the bottom edge of the UIScreen
.. and it is.
If the math is correct, then I am obviously not understanding the math of the layout .. because the UIBezierPath
is not showing.
The math appears correct .. but the UIBezierPath
just is not showing.
So where is my brain off-center?