jeudi 21 janvier 2016

Swift. SpriteKit. Getting sprite to create randomly on X axis

I've been trying to make the sprite spawn any where on the x axis, but when i use this code the spawn out side of the screen and not in a viewable area. If it helps i'm using an iPhone 6s.


let Enemy = SKSpriteNode(imageNamed: "EnemyGalaga.png")//the pic name
    //setup random spawning
    let MinValue = self.size.width / 7
    let MaxValue = self.size.width  - 200
    let SpawnPoint = UInt32(MaxValue - MinValue)
    Enemy.position = CGPoint(x: CGFloat(arc4random_uniform(SpawnPoint)), y: self.size.height)


    let action = SKAction.moveToY(-600, duration: (enemySpeed))//where to go and how long it takes
    Enemy.runAction(SKAction.repeatActionForever(action))


I would be extremely grateful if you could solve this problem

Thank You-




Aucun commentaire:

Enregistrer un commentaire