swiftsprite-kitcgpoint

Create random CGPoint with Swift


So, I'm trying to develop a simple game written in Swift, but I'm having trouble doing a pretty simple thing. I can't manage to create a random CGPoint... When using arc4random, a compiler error shows up telling me that I can't use Int32 in a CGPoint. So, Is there any way to do this? Any workaround? Thanks!


Solution

  • hi what about constructing an Int? Int(arc4random())

    e.g.

    var p = CGPoint(x:Int(arc4random()%1000),y:Int(arc4random()%1000))