0
SKYSapeNode의 하위 클래스에서 초기화 프로그램을 사용할 수 없습니다. 이 문제를 해결하기 위해 여기에 게시 된 예제를 시도했습니다. Adding Convenience Initializers in Swift Subclass. 내가 사용하고있는 코드는 다음과 같습니다. 편의 초기화를 초기화Swift SKShapeNode가 초기화 프로그램을 허용하지 않습니다.
class Ground1 : SKShapeNode {
override init() {
super.init()
print("Hello1")
}
convenience init(width: CGFloat, point: CGPoint) {
var points = [CGPoint(x: -900, y: -300),
CGPoint(x: -600, y: -100),
CGPoint(x: -100, y: -300),
CGPoint(x: 2, y: 150),
CGPoint(x: 100, y: -300),
CGPoint(x: 600, y: -100),
CGPoint(x: 900, y: -300)]
self.init(splinePoints: &points, count: points.count)
lineWidth = 5
strokeColor = UIColor.orange
physicsBody = SKPhysicsBody(edgeChainFrom: path!)
physicsBody?.restitution = 0.75
physicsBody?.isDynamic = false
print("Hello2")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
()를 무시하고 사용되지 않습니다. 장면에 쉐이프가 추가되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까 ?
지상 추가를 위해 사용한 코드는 무엇입니까? – Sweeper
나는 gameScene에 인스턴스를 만들고, ground = ground1()이라고하고, 장면에 인스턴스를 추가한다. Addchild (gound). 나는 콘솔에서 print hello1을 얻지 만 프린트는 안된다. hello2 – hoboBob
이'let ground = Ground1 (width : 10, point : CGPoint.zero)'와'addChild (ground)'를 시도해 보라. 'override init() {...}'및'필요한 init {...}'을 삭제할 수 있습니다. – 0x141E