The only reason I'm attempting this programmatically is so I can access the locations of each tile, making it possible to manipulate the grid. I've looked at about 15 different tutorials using other programming languages, but even with that knowledge, I'm still having a very difficult time creating one in Swift.
I've tried creating a nested for loop but I'm not even sure if the code inside the loops make logical sense for creating an isometric grid, I just took it off of one of the tutorials I found:
func generateGrid() {
for (var i = 0; i < 5; i++) {
for (var j = 5; j >= 0; j--){
tile.position = CGPoint(x: (j * Int(tile.size.height) / 2) +
(i * Int(tile.size.width) / 2),
y: (i * Int(tile.size.height) / 2) -
(j * Int(tile.size.width) / 2))
addChild(tile)
}
}
}
Then I tried to call this in the "didMoveToView" function, but obviously you can't add the same node more than once.
Please give me any direction that you can.
for (var j=...
loop:let tile=SKSpriteNode()/*do whatever setup here*/\*set the position*/
– Allegro