2016-07-19 36 views
0

這是讓我走的那些問題之一「我怎麼辦?」在'Cat'類型上使用實例成員'meow'是否意味着使用'Cat'類型的值?

這是編譯器錯誤我得到:

Use of instance member 'getAttackUPSequence_Frames' on type 'SKFootmanSprite' did you mean to use a value of type 'SKFootmanSprite' instead?

我得到這個爲我所有_Frames變量。 這裏是我的公共屬性SKFootmanSprite:

// ATTACK 
static let attackUp_Frames = getAttackUPSequence_Frames() 
static let attackDown_Frames: [SKTexture] = getAttackDOWNSequence_Frames() 
static let attackLeft_Frames: [SKTexture] = getAttackLEFTSequence_Frames() 
static let attackRight_Frames: [SKTexture] = getAttackRIGHTSequence_Frames() 

static let attackUpRight_Frames: [SKTexture] = getAttackUPRIGHTSequence_Frames() 
static let attackUpLeft_Frames: [SKTexture] = getAttackUPLEFTSequence_Frames() 

static let attackDownLeft_Frames: [SKTexture] = getAttackDOWNLEFTSequence_Frames() 
static let attackDownRight_Frames: [SKTexture] = getAttackDOWNRIGHTSequence_Frames() 

這是該得到的攻擊順序的功能之一:

func getAttackUPSequence_Frames() -> [SKTexture] { 
    var textures = [SKTexture]() 
    for var i = 1; i < 7; i+=1 { 
     let imageName = "footman_attack_up0" + String(i) 
     textures.append(SKTexture(imageNamed: imageName)) 
    } 
    let imageName = "footman_up_stand" 
    textures.append(SKTexture(imageNamed: imageName)) 
    return textures 
} 

我想我的精靈幀使用let而不是var。 (由蘋果官方雨燕教科書把使用let代替var這樣的事情非常強調的。)

回答

0

你的問題是,你的let變量是靜態的,但你的函數不是。

你應該嘗試通過使你的函數getAttackUPSequence是靜態的。

這個錯誤意味着你試圖從實例的「外部」訪問實例成員(函數)。

0

是的,你的函數getAttackUPSequence應該是靜態的。

相關問題