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