0
我有一個spriteNode它有一個黑色圓圈的默認紋理,我已經把它放在屏幕的中心。我也有一個包含4個紋理的數組。我想要做的是當我點擊屏幕中心的黑色圓圈時,從數組中隨機選擇一個SKTexture並變爲設置紋理。我在想didBeginTouches中的代碼行,但我堅持如何真正執行這個想法。謝謝你的幫助。 :)Xcode6 Swift。 arc4random使用數組紋理
var array = [SKTexture(imageNamed: "GreenBall"), SKTexture(imageNamed: "RedBall"), SKTexture(imageNamed: "YellowBall"), SKTexture(imageNamed: "BlueBall")]
override func didMoveToView(view: SKView) {
var choiceBallImg = SKTexture(imageNamed: "BlackBall")
choiceBall = SKSpriteNode(texture: choiceBallImg)
choiceBall.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2)
self.addChild(choiceBall)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
choiceBall.texture = SKTexture(imageNamed: arc4random(array))
//error: Cannot assign a value of type 'SKTexture!' to a value of type 'SKTexture?'
}