Monday, January 1, 2024
HomeiOS Developmentios - Swift 2D array with Sprites

ios – Swift 2D array with Sprites


I’ve been out of the loop with swift for some time and I am caught with an Array downside.
I get the sensation I am approaching all of it unsuitable and I used to be doing this to scrub up repetitive code. I’ve a loop inside a loop which appears to be working with the exception that once I output I get all 4 iterations from the primary loop which in a method is ok as I need all for however I wish to put them in a variable earlier than the second iteration begins… I hope this is smart and I could possibly be miles of the way in which I am doing it any assist could be appreciated.

struct Motion {
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))
     }
    /*offers me all 4 iterations of the for loop I wish to in some way get iteration 1,2,3,4 and assign them to glabal variables*/
 print(e1Frames[0])
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments