func createPaddles() -> SKNode {
let container = SKNode()
let colors = [SKColor.green, SKColor.blue, SKColor.red, SKColor.green, SKColor.blue]
let width = self.frame.size.width
let height = self.frame.size.height
for i in 0...4 {
let node = SKShapeNode(rectOf: CGSize(width: self.frame.size.width / 3, height: self.frame.size.height * 0.15))
node.fillColor = colors[i]
node.strokeColor = colors[i]
node.zPosition = 100
node.position = CGPoint(x: -width * 1/6 + width / 3 * i, y: height * 0.075)
container.addChild(node)
}
return container
}
node.position is giving me an error saying it's too complex. Is this because calculating the frame width twice in one equation is too much for the compiler? Seems unlikely and this doesn't seem overly complex to me. Am I missing something here?
EDIT: Great group effort from everyone, thank you! This is what eventually worked (a combination of a few different answers):
node.position = CGPoint(x: -width / 6.0 + width / 3.0 * CGFloat(i), y: height * 0.075)