0
我想從Objective-C切換到Swift,但我無法理解如何聲明SKSpriteNode屬性。我需要這個以便從每個功能訪問它。 目標C,它是:如何在Swift中全局聲明SKSpriteNode
@property (nonatomic, strong) SKSpriteNode *selectedNode;
我想從Objective-C切換到Swift,但我無法理解如何聲明SKSpriteNode屬性。我需要這個以便從每個功能訪問它。 目標C,它是:如何在Swift中全局聲明SKSpriteNode
@property (nonatomic, strong) SKSpriteNode *selectedNode;
在迅速的,你會像
class YourClass: UIViewController
{
var selectedNode: SKSpriteNode
}
取決於當你實例化SKSpriteNode上,你會在SKSpriteNode
之後有一個!
。
另外,這個變量可以在你的班級之外訪問。這意味着你可以不喜歡
var myObject = YourClass()
myObject.selectedNode = ...
東西,如果你希望把它變成私有,你可以這樣做:
private var selectedNode: SKSpriteNode
我不知道爲什麼我不能訪問變量var精靈:SKSpriteNode如果self.sprite!= nil – user2414590 2014-09-27 10:17:53