UIBezierPath *not* showing?

39 Views Asked by At

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 1024 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 1366 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?

1

There are 1 best solutions below

3
John Love On

The following looks suspiciously like the answer .. but I definitely don't understand why it is happening:

The suspicious line is:

if let ourScene = GameScene(fileNamed: "GameScene") {
    print("here")   // this shows
    ourScene.addChild(theTrackShapeNode)   // does *not* show?
}

It is totally clear to me that I am in a total fog ...

I set up my GameScene.sks within Xcode, which I set as 1366 x 1366

The frame: designation below is in line with the anchor setting .. so the fog continues as to why the blue UIBezierPath is not showing

//  print("ourScene = \(ourScene)")
//  ourScene = <SKScene> name:'GameScene'
//                       frame:{{-683, -683}, {1366, 1366}}
//                       anchor:{0.5, 0.5}