제 첫 번째 iPhone 게임에 대해 'Alien
'일반용 '청사진'클래스를 작성하려고합니다. 이 클래스는 모든 실제 외계 서브 클래스에 의해 상속 될 소수의 프로퍼티와 메소드를 포함합니다. 즉, Alien
에는 실제로 텍스처가 없어야하며 자체 정의 된 값 집합이 없어야합니다.Swift에서 SKSpriteNode를 상속 한 기본 클래스 인스턴스화
//Generic alien type: a blue-print of sorts
class Alien:SKSpriteNode{
let velocityVector:CGVector
let startPos:CGPoint
init(texture:SKTexture, startPosition startPos:CGPoint,moveSpeed: CGFloat,velocityVector:CGVector){
super.init(texture: texture, color: UIColor.clearColor(), size: texture.size())
self.velocityVector = normalizeVector(velocityVector)
self.position = position
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
때마다 나는 다음과 같은 오류의 소수로 실행이 설정 시도 :
"Use of instance member 'normalizeVector' on type GameScene; did you mean to use a value of type GameScene instead?"
normalizeVector
은 (GameScene 이내) Alien
클래스 위에 기록되는 기능입니다. 이것이 GameScene 내의 정상적인 기능이기 때문에 이것이 무엇을 의미하는지 모르겠습니다. 나는이 비트를 제거하면, 난 여전히 같은 오류가 나타날 수
"Property self.velocityVector is not initialized at super.init call"
나는 내가 SKSpriteNode의 서브 클래스를 만들고 있어요 때문에 super.init()
은 필요하다고 생각했기 때문에 혼란 스러워요하고이 필요하지 않을 것이라고 건네받은 서브 클래스 고유의 프롭퍼티
마지막으로이 청사진 클래스가 "표시"되지 않으므로 실제 텍스처가없는 super.init()
을 호출 할 수있는 방법이 있습니까? 클래스/초기화에 대한 사과 문서를 살펴본 후에도 여전히 문제가 있습니다. 어떤 도움이라도 좋을 것입니다.
왜 GameScene에서 'Alien'을 정의하고 있습니까? 별도의 파일이 더 적절할 것입니다. –
@appzYourLife GameScene 외부에서 모든 수업을 작성해야합니까? 일부 조사를 해본 결과 많이 찾지 못했습니까? 게임 논리는 어떻습니까? – Sam
다른 파일을 다른 클래스로 작성하는 것이 좋습니다. [SpriteKit 프로그래밍 가이드] (https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html)도 읽어보십시오. –