ios - How to load sprite sheets from web API in SpriteKit -


i'm new spritekit, , question how load sprite sheets web api.

currently, have api returns big png image, contains sprite sheets, , json individual frame information. (file , json generated texturepacker) api looks this:

enter image description here

the format likes .atlasc folder, contains big image , plist (xml) file.

i thinking downloading image , plist file , save in disk load. however, sktextureatlas.init(named: string) can load app bundle.

in 1 word, want load sprite animation web @ runtime.

i have control of api, can update api accomplish goal.

the way i've figured out downloading image, create sourcetexture, like: let sourcetexture = sktexture(image: image)

then use frame information in json create individual textures method init(rect rect: cgrect, intexture texture: sktexture)

sample code is:

    var textures: [sktexture] = []      let sourcetexture = sktexture(image: image)     frame in spritesheet.frames {         let rect = cgrect(x: frame.frame.origin.x / spritesheet.size.width,                           y:  1.0 - (frame.frame.size.height / spritesheet.size.height) - (frame.frame.origin.y / spritesheet.size.height),                           width: frame.frame.size.width / spritesheet.size.width,                           height: frame.frame.size.height / spritesheet.size.height)         let texture = sktexture(rect: rect, intexture: sourcetexture)         textures.append(texture)     } 

Comments