I have code which generates random background images, but for some reason when the code is called my game glitches for a split of a second, which is very noticeable. After hours of commenting out my code, I've narrowed it down to one of my random number generates. I have two random number generators, one that generates a number between 0 and 2 and one that generates a number between 0 and 162. The thing that has me stumped is, the generator which generates a number between 0 and 2 is the one creating the glitch???
Here is my code below, can anybody see something I'm missing?
randomLandscape = CGFloat(arc4random_uniform(UInt32(3)))
randomDistanceLandscape = CGFloat(arc4random_uniform(UInt32(sizePreviousLandscapeWidth2)))
nodeLandscapeA = SKSpriteNode(imageNamed: "A\(Int(countWorld))2\(Int(randomLandscape))")
nodeLandscapeA.name = "landscapeA"
nodeLandscapeA.zPosition = CGFloat(arrayLandscapeZPosition[Int(countWorld)] + 3)
nodeLandscapeA.position.y = nodeLandscapeA.size.height/2
nodeLandscapeA.position.x = positionPreviousLandscapeX2 + sizePreviousLandscapeWidth2/2 + nodeLandscapeA.size.width/2 + randomDistanceLandscape
nodeLandscapeB = SKSpriteNode(imageNamed: "B\(Int(countWorld))2\(Int(randomLandscape))")
nodeLandscapeB.name = "landscapeB"
nodeLandscapeB.zPosition = CGFloat(arrayLandscapeZPosition[Int(countWorld)] + 2)
nodeLandscapeB.position.y = nodeLandscapeA.position.y
nodeLandscapeB.position.x = nodeLandscapeA.position.x
Note, if I enter randomLandscape = 1, the glitch disappears.