0
我一直在學習spritekit,但是我在super.init中遇到了一些困難。我來自Java的背景,並想知道爲什麼我收到錯誤: 「Super.Init在初始化程序中多次調用」Super.Init在初始化程序中多次調用
我想要實現的是一個構造函數,指定適當的休息紋理到角色,同時設置紋理數組,以便我可以調用它,而不必擔心傳遞值。
我已經看過文檔,但我認爲我的咖啡水平已經耗盡,因爲我真的無法理解super.init爲什麼會自己調用。任何幫助,你可以提供將不勝感激。我曾搜索類似的問題,但找不到一個,如果我誤以爲這個鏈接的答案將同樣讚賞。
class CharClass : SKSpriteNode
{
var textureAtlas = SKTextureAtlas()
var textureArray = [SKTexture]()
init() {
textureAtlas = SKTextureAtlas(named:"Org")
//likely should be a passed variable instead
for i in 1 ... textureAtlas.textureNames.count{
var Name = String();
if(i<10)
{
Name = "cWalk000\(i).png"
}
else
{
Name = "cWalk00\(i).png"
}
textureArray.append(SKTexture(imageNamed: Name));
let texture = SKTexture(imageNamed: textureAtlas.textureNames[0]);
super.init(texture:texture, color: UIColor.clear, size:texture.size())
self.size = CGSize(width:71 , height: 131);
self.position = CGPoint(x: -282.52, y:-141.5);
self.run(SKAction.repeatForever(SKAction.animate(with: textureArray, timePerFrame: accelSpeed)))
}
}
問題是你在一個循環內調用'super.init'。不要這樣做。只調用'super.init'一次。 – rmaddy
謝謝!因爲我忘記關閉我的循環,所以我會睡一覺 – Blundabus