2014-06-12 61 views
6

我試圖自己將SKSpriteNodes添加到函數的視圖中,但Xcode不會允許我這樣做。它給了我爲什麼我不能在func中使用自我Swift

func indicate() { 
if test == 0 { 
    var large = ((CGFloat(largest)*54) - 29) - selectedNode.position.x 
    var small = selectedNode.position.x - ((CGFloat(smallest)*54) - 29) 

    indicatorRight.position = CGPointMake(selectedNode.position.x + large, selectedNode.position.y) 
    indicatorRight.userInteractionEnabled = true 
    indicatorRight.zPosition = 0.5 

    indicatorLeft.position = CGPointMake(selectedNode.position.x - small, selectedNode.position.y) 
    indicatorLeft.userInteractionEnabled = true 
    indicatorLeft.zPosition = 0.5 


    println(indicatorLeft.position) 
    // println(smallest) 
    self.addChild(indicatorRight) 
    self.addChild(indicatorLeft) 

    } 


} 
+3

什麼是包含內的指示功能?這是一堂課嗎? –

+0

該功能出現在什麼外部環境中? – Tommy

+0

它不是在一個班級或任何東西。 – Nas5296

回答

6

納斯,

對於FUNC錯誤「未解決的標識符‘自我’的使用」,以便能夠使用「自我」,它需要一個類的一部分。

「自我」指的是應用方法(或使用Swift說法:「func」)的當前實例。如果在全局級定義了func,那麼如果是而不是類的一部分,則它不能與類的實例關聯。

因此不可能使用「自我」在這方面。

18

確認方法,提出在類括號和右括號

A級 {

//你需要這裏定義的方法

}

//你可能已經在這裏宣佈它。

相關問題