5
我更新了迅速3.代碼我已經創建了我的spritekit對象,在迅速2.工作然而自定義路徑,現在我得到一個編譯錯誤:CGPath不是在斯威夫特工作3
Nil is not compatible with expected argument type 'Unsafe Pointer CGAffineTransform'
let offsetX = player.size.width * player.anchorPoint.x
let offsetY = player.size.height * player.anchorPoint.y
let path = CGMutablePath()
CGPathMoveToPoint(path, nil, 10 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 10 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 28 - offsetX, 40 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 46 - offsetY)
CGPathAddLineToPoint(path, nil, 6 - offsetX, 36 - offsetY)
CGPathAddLineToPoint(path, nil, 6 - offsetX, 18 - offsetY)
path.closeSubpath()
錯誤是在添加到路徑時在第二個參數中傳遞nil。我試圖在不安全的指針傳遞像這樣:
var tr = CGAffineTransform.identity
CGPathMoveToPoint(path, &tr, 10 - offsetX, 16 - offsetY)
....
但隨後得到了另一個奇怪的錯誤。
CGPathMoveToPoint is unavailable. Use move(to: transform:)
但是,沒有參數名稱的移動函數。然而,有一個舉措(toParent:)。
謝謝!沒有想過檢查成員函數的變量。 – patrickd