dimanche 2 août 2015

Spawn a SKSpriteNode between two values randomly

I am trying to work out how to spawn a SKSpriteNode between two positions (located on the screen) randomly in Swift.

This is what I came up with, but it does spawn Nodes outside the screen dimensions altough I defined two points inside the screen bounds!

    /* Spawning Values */
    var MinSpawnValue = self.size.width / 8
    var MaxSpawnValue = self.size.width - self.size.width / 8
    var SpawnPosition = UInt32(MaxSpawnValue - MinSpawnValue)
    /* Node Positioning */
    Node.position = CGPointMake(CGFloat(arc4random_uniform(SpawnPosition)),CGRectGetMidY(self.frame))




Aucun commentaire:

Enregistrer un commentaire