【发布时间】:2015-07-30 19:56:58
【问题描述】:
我一直在绞尽脑汁,到处搜索,试图找出如何在屏幕上生成一个随机位置来生成一个圆圈。我希望这里有人可以帮助我,因为我完全被难住了。基本上,我试图创建一个形状,当用户触摸时,它总是在屏幕上的随机位置生成。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenHeight = screenSize.height
let screenWidth = screenSize.width
let currentBall = SKShapeNode(circleOfRadius: 100)
currentBall.position = CGPointMake(CGFloat(arc4random_uniform(UInt32(Float(screenWidth)))), CGFloat(arc4random_uniform(UInt32(Float(screenHeight)))))
self.removeAllChildren()
self.addChild(currentBall)
}
如果你们都需要更多我的代码,那么真的没有更多了。但是感谢您提供的任何帮助! (重申一下,这种代码是可行的……但大多数生成的球似乎都在屏幕外生成)
【问题讨论】:
标签: ios swift random arc4random