mardi 20 décembre 2016

playscene sprite kit random apparition of sprite

I have this code:

class PlayScene: SKScene {
let forest = SKSpriteNode(imageNamed: "forest")
let skeleton = SKSpriteNode(imageNamed: "skeleton")
let elf = SKSpriteNode(imageNamed: "elf")
let orc = SKSpriteNode(imageNamed: "orc")
let rand = Int(arc4random_stir())

override func didMoveToView(view: SKView) {
    print("Second view")
    self.forest.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    self.elf.position = CGPoint(x: 350, y: 300)
    addChild(self.forest)
    addChild(elf)
    print(rand)
    //if(rand >= 5){
        self.skeleton.position = CGPoint(x: 100, y: 300)
        addChild(skeleton)
    } /*else{
        self.orc.position = CGPoint(x: 100, y: 300)
        addChild(orc)
    }

}*/

Who works when he wants. And I don't understand why, I think is because of the relation parent/children, but I don't know what to change to not make them in conflict. Sometimes the elf appears, sometimes not, same for skeleton and orc... So I'm lost. Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire