我正在开发一款游戏,其中我的机车遵循模仿椭圆形轨道的
UIBezierPath
。
以下的数学是不是“相加”..如果是的话,我显然不理解布局的数学。
底线=以下代码不显示
UIBezierPath
。
这是创建这个的代码
UIBezierPath
..请注意评论中的数学:
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
在纵向模式下,
UIScreen
的尺寸为 1024 x 1366,轨道尺寸为 1024 x 476,其顶部边缘距 UIScreen
中心向下 207。
在横向模式下,
UIScreen
的尺寸为 1366 x 1024,轨道尺寸为 1366 x 238,其顶部边缘距 UIScreen
中心向下 274。
在两种模式下,轨道的底部边缘都应该与
UIScreen
的底部边缘齐平 .. 确实如此。
如果数学是正确的,那么我显然不理解布局的数学..因为UIBezierPath
数学看起来是正确的..但是
UIBezierPath
只是没有显示。
那么我的大脑哪里偏离了中心?
以下内容看起来可疑地像答案..但我绝对不明白为什么会发生:
可疑线路是:
if let ourScene = GameScene(fileNamed: "GameScene") {
print("here") // this shows
ourScene.addChild(theTrackShapeNode) // does *not* show?
}
我完全清楚我完全陷入了迷雾......
我在 Xcode 中设置了
GameScene.sks
,将其设置为 1366 x 1366
鉴于此,我不明白下面的
frame:
名称?
// print("ourScene = \(ourScene)")
// ourScene = <SKScene> name:'GameScene'
// frame:{{-683, -683}, {1366, 1366}}
// anchor:{0.5, 0.5}