Reputation: 470
I am developing a small game but I'm stuck on this. I want to generate a random position for an SKSpriteNode called div. I have this code
let random = arc4random() % UInt32(self.frame.size.width)
let random1 = arc4random() % UInt32(self.frame.size.height)
div.position = CGPoint(x: Int(random), y: Int(random1))
self.addChild(div)
I can't figure out what's wrong and why the div is sometimes out of the frame and not visible. Does anyone has a good solution for this? Any help is appreciated! Thanks!
Upvotes: 1
Views: 55