2016-09-16 5 views
5
내가 지금은 컴파일러 오류 얻을, 그러나 빠른 2에서 '내 spritekit 개체에 대한 사용자 지정 경로를 생성 한 빠른 3에 대한 코드를 업데이트하고

: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 :)이있었습니다.

답변

15

대부분의 구문은 Swift 3에서 변경되었지만 CGPathMoveToPoint와 같은 API 메소드를 제거하지 않았으며 이름이 아래와 같이 변경되었습니다.

let path = CGMutablePath() 
path.move(to: CGPoint(x: 10.0, y: 10.0)) 
path.addLine(to: CGPoint(x: 10.0, y: 10.0)) 
+0

감사합니다! 변수를 점검하여 멤버 함수를 생각하지 않았습니다. – patrickd

관련 문제