0
我想重複顯示兩張遊戲卡中的一張,每當用戶觸摸deckOfCards
。在SpriteNode上重複動作
到目前爲止,我得到了它的工作,但是當我再次點擊deckOfCards
時,卡片不會改變。試着用10個或更多的卡片名稱,也沒有工作。
class GameScene: SKScene {
let cardname = ["card2", "ace"]
let randomNumber = Int(arc4random_uniform(13))
var deckOfCards = SKSpriteNode()
var yourCard = SKSpriteNode()
override func didMove(to view: SKView) {
deckOfCards = self.childNode(withName: "deckOfCards") as! SKSpriteNode
yourCard = self.childNode(withName: "yourCard") as! SKSpriteNode
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view?.endEditing(true)
for touch: AnyObject in touches {
let location = touch.location(in: self)
let node : SKNode = self.atPoint(location)
if node.name == "deckOfCards" {
yourCard.texture = SKTexture(imageNamed: "\(cardname[randomNumber])")
}
}
}
快速回答,點上並解決問題。非常感謝 – junxi