【发布时间】:2017-09-15 11:24:47
【问题描述】:
每当用户触摸deckOfCards时,我想重复显示两张游戏卡中的一张。
到目前为止,我让它工作了一次,但是当我再次点击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])")
}
}
}
【问题讨论】:
标签: ios swift swift3 skspritenode touchesbegan