I'm very new to coding and would appreciate some help with a small game I'm making to learn. So I have a circle and I'm trying to create objects at every 10 degree interval around the circle. I tried this:
override func didMoveToView(view: SKView) {
self.spawnArrows()
}
func spawnArrows() {
for var i = 0; i < 36; i++ {
let arrow = self.createArrow(specificPointOnCircle(Float(self.frame.size.width), center: CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame)), angle: Float(i * 10)))
self.addChild(arrow)
}
}
func specificPointOnCircle(radius:Float, center:CGPoint, angle:Float) -> CGPoint {
let theta = angle * Float(M_PI) + 2.0
let x = radius * cosf(theta)
let y = radius * sinf(theta)
return CGPoint(x: CGFloat(x) + center.x, y: CGFloat(y) + center.y)
}
func createArrow(position: CGPoint) -> SKSpriteNode {
let arrow = SKSpriteNode(imageNamed: "Arrow.png")
arrow.zPosition = 2
arrow.size = CGSize(width: self.frame.size.width * 0.12, height: self.frame.size.width * 0.025)
arrow.position = position
return arrow
}
But nothing at all is showing up. Is my math wrong somewhere, or my syntax, or perhaps both? Any help is appreciated.
spawnArrows()
. It doesn't seem to change at all. Angle is the angle of your SpriteNode. Sorry, but I have no time to check further atm... :( – Akainolet theta = angle * Float(M_PI) / 180
– Knight0fDragonFloat(self.frame.size.width)/10
and changing the radian formula tolet theta = angle * Float(M_PI) / 180
solved the problem for me. You should make that an answer @Knight0fDragon – Akaino