ios – Swift 2D array with Sprites


I have been out of the loop with swift for a while and I’m stuck with an Array problem.
I get the feeling I’m approaching it all wrong and I was doing this to clean up repetitive code. I have a loop within a loop which seems to be working with the exception that when I output I get all 4 iterations from the first loop which in a way is fine as I want all for but I want to put them in a variable before the second iteration starts… I hope this makes sense and I could be miles of the way I’m doing it any help would be appreciated.

struct Action {
static var arraySprites :[SKTexture], [SKTexture]()
static var Idle = [SKTexture]()
}
var actions = ["idle", "walk", "run", "jump"]
var sprites = ["Idle", "Walk", "Run", "Jump"]
for (e1, e2) in zip(actions, sprites) {
    
    let e1Atlas = SKTextureAtlas(named: "\(e2)")
    var e1Frames: [SKTexture] = []
    let e1Images = (e1Atlas.textureNames.count-1)
    for i in 0...(e1Images) {
     let sprite = String(format: "%03d", i);
     let e1Texture = "\(e1)\(sprite)"
     e1Frames.append(e1Atlas.textureNamed(e1Texture))
     }
    /*gives me all four iterations of the for loop I want to somehow get iteration 1,2,3,4 and assign them to glabal variables*/
 print(e1Frames[0])
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img