所以我需要从圆周边的随机点产生游戏敌人.这是我到目前为止的代码,感觉非常接近工作,但不是:
let enemy = SKShapeNode(circleOfRadius: 5)
func enemyGenerator() {
//takes an x value and calculates the corresponding y coordinate on the circle.
func enemyYSpawnPosition(x: CGFloat) -> CGFloat {
return sqrt(104006.25 - (x * x))
}
//randomly selects an x value from a range of acceptable values.
func enemyXSpawnPosition() -> CGFloat {
func randRange (lower: Int , upper: Int) -> Int {
return lower + Int(arc4random_uniform(UInt32(upper - lower + 1)))
}
var xValue = randRange(-2.5, 322.5)
return CGFloat (xValue)
}
//used …Run Code Online (Sandbox Code Playgroud)