在SpriteNode上重复操作

时间:2017-09-15 11:24:47

标签: ios swift swift3 skspritenode touchesbegan

每当用户触摸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])")
        }
    }
}

1 个答案:

答案 0 :(得分:1)

randomNumber是$select->from(array('u' => 'dbt_users'), array('firstname','lastname')) ->joinLeft(array('amanager' => 'dbt_assign_manager'), 'u.id = amanager.pm_id', array('id','pm_id','scheme_id','created','changed','status')) ->joinLeft(array('p' => 'dbt_scheme'), 'p.id in(amanager.scheme_id)', array('p.scheme_name as projectname')) ->joinLeft(array('roles' => 'dbt_roles'), 'u.role = roles.id', array('title as role_name')) ->where('u.status = 1 and u.role in(4,6) and u.createdby=7') ->where('u.id in( select distinct ux.id from dbt_users as ux left outer join dbt_assign_manager as ax on ux.id = ax.pm_id left outer join dbt_scheme as sx on ax.scheme_id = sx.id left outer join dbt_ministry as dx on dx.id= sx.ministry_id where dx.id = 81'); 之外的常量。 永远不会改变。将其放在touchesBegan内。

touchesBegan