2014-06-12 41 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级 {

//你需要这里定义的方法

}

//你可能已经在这里宣布它。

相关问题