Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var playerAtlas = SKTextureAtlas()
- var playerAnimation = [String : [SKTexture]]()
- let playerAnimationTypes = ["run", "static", "jump", "armed_static", "armed_run", "armed_jump"] // Player's animations
- var playerAnimationsArray = [String]() // Array with all player Sprites
- var playerAnimationSpritesPrefix = "Player_"
- let runAnimationTime = 0.1
- var actualAnimation = [SKTexture]()
- playerAtlas = SKTextureAtlas(named: "Player_anim")
- for i in 0 ..< playerAtlas.textureNames.count {
- playerAnimationsArray.append(playerAtlas.textureNames[i]) // Gets all the animations image names
- }
- for i in 0 ..< playerAnimationTypes.count {
- let animations = playerAnimationsArray.filter{$0.hasPrefix(playerAnimationSpritesPrefix + playerAnimationTypes[i])}.sort() // Gets all image names for a specific type of animation (eg: Player_run0.png, Player_run1.png, etc)
- for j in 0 ..< animations.count {
- if playerAnimation[playerAnimationTypes[i]] == nil {
- playerAnimation[playerAnimationTypes[i]] = [] // Creates array if doesn't exist
- }
- playerAnimation[playerAnimationTypes[i]]!.append(SKTexture(imageNamed: animations[j])) // Add texture to make the animation
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement