swift - Array with nodes at each index -


I am creating a game with Sprite kit in Spirit, and there are three nodes in my three positions:

  self.size.width * 1/6 // left self.size.width * 1/6 // middle itself. Size.width * 1/6 // right  

I have created an array with three positons so that they can be called randomly:

  RedXx X [[Sprax. Wide. 1/6, speaker width * 3/6, self.size.width * 5/6] // the array with three positions randomIndex = Int (arc4random_uniform (UInt32 (randomX.count))) do xPos: CGFloat = randomX [randomIndex]  

I have another array with three nodes of the gems:

  to randomJewels = [SKSpriteNode (imageNamed: "jewel1"), SKSpriteNode (ImageNamed: "jewel2"), SKSpriteNode (imageNamed: "jewel3"),]  

and I have set the status and size of my generated node:

  to 1 = random Jewels [Int (arc4random_uniform (3))] jewel1.anchorPoint = CGPointMake (0.5, 0) jewel1.position = CGPointMake (xPos, self.size.height / 2) jewel1.size.width = 40 Jewel1.s ize.height = 20 self.addChild (jewel1)  

Three steps must be taken to three random node (Jewel), but if I am creating two other jewelry, they have a The only situation can be because they have three different positions.

How can I do that jewelry catches up to three positions? It can not be zero state, there is a jewel on every x position! Thanks!

When you make a jewel, you need to remove its image and position so that another Neither can jewelery be as follows:

name = ["gem 1", "gem 2", "jewel 3"] // names of jewel pictures, var xpositions = [size.width * 1 / 6, size.width * 3/6, size.width * 5/6] // posible for x I positions in 0 .. & lt; xPositions.count {// Create a jewel for every X position to imageIndex = Int (arc4random_uniform (UInt32 (imageNames.count))) Jewel = SKSpriteNode (do imageNamed: imageNames [imageIndex]) imageNames.removeAtIndex (imageIndex) // this image remove any other jewel is the xPositionIndex = Int (arc4random_uniform (UInt32 (the xPositions be. count))) jewel.position = CGPoint (X: xPositions [xPositionIndex], Y: size.height / 2) xPositions.removeAtIndex (XPositionIndex) // If this situation is far away then no other Jewel this setup is // jewel and can be added for this view}

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -