我最近更新到Xcode 7 Beta,現在我收到一條錯誤消息「實例成員'視圖'不能在類型'GameScene'中用於第5行。有任何想法如何解決這個此外,如果你想成爲額外的幫助,請參閱我的其他問題:ConvertPointToView Function not working in Swift Xcode 7 Beta實例成員'視圖'不能在類型'GameScene'上使用
import SpriteKit
class GameScene: SKScene {
var titleLabel: StandardLabel = StandardLabel(x: 0, y: 0, width: 250, height: 80, doCenter: true, text: "Baore", textColor: UIColor.redColor(), backgroundColor: UIColor(white: 0, alpha: 0), font: "Futura-CondensedExtraBold", fontSize: 80, border: false, sceneWidth: view.scene.frame.maxX)
override func didMoveToView(view: SKView) {
self.scene?.size = StandardScene.size
self.view?.addSubview(titleLabel)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in (touches) {
let location = touch.locationInNode(self)
}
}
override func update(currentTime: CFTimeInterval) {
}
}
什麼是StandardLabel? – ABakerSmith
@ABakerSmith Line 5.不要擔心標準標籤,我會傳遞它的有效參數。我可以告訴你,如果你想,但它只是一堆初始化。問題是'view',我得到錯誤信息''view'不能用於類型'GameScene'「 –
@ABakerSmith好吧,你使用的是Xcode beta 7嗎?不,StandardLabel是UILabel的一個子類。它與self.view?.addSubview(titleLabel)沒有任何關係。它僅適用於提到'視圖'時的第5行。 –