extension SKPhysicsBody {
/// anchorPoint version of init(rectangleOfSize:center:)
convenience init(rectangleOfSize s: CGSize, withAnchorPoint anchorPoint: CGPoint) {
var center = CGPoint()
center.x = (s.width/2) - (s.width * anchorPoint.x)
center.y = (s.height/2) - (s.height * anchorPoint.y)
self.init(rectangleOfSize: s, center: center)
}
}
-[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0'
這個錯誤這是我在代碼
// redBox is a typical SKSpriteNode()
redBox.physicsBody = SKPhysicsBody(rectangleOfSize: redBox.frame.size, withAnchorPoint: redBox.anchorPoint)
怎麼稱呼我基本上要延長SKPhysicsBody
類,以提供一個方便初始值化程序到它的工廠方法
你是怎麼調用初始化程序的? – Cristik
'redBox.physicsBody = SKPhysicsBody(rectangleOfSize:redBox.frame.size,withAnchorPoint:redBox.anchorPoint)' –
我當前的解決方法是使用工廠方法'SKPhysicsBody.bodyWithRectangleOfSize(:withAnchorPoint:)'返回物理主體。這完全感覺不到迅捷,因爲所有的obj-c工廠都很好地映射到各自的init方法。 –