我正在开发一个小游戏,但我坚持这个。我想为一个名为 div 的 SKSpriteNode 生成一个随机位置。我有这个代码
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)
我不知道出了什么问题,也不知道为什么 div 有时会超出框架并且不可见。有人对此有好的解决方案吗? 任何帮助表示赞赏!谢谢!
最佳答案
尝试在您的 didMoveToView
中设置它,
self.size = view.bounds.size
关于ios - 框架中的随机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32895830/