Advertisement
SergioRP

Untitled

May 7th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.18 KB | None | 0 0
  1. var playerAtlas = SKTextureAtlas()
  2. var playerAnimation = [String : [SKTexture]]()
  3. let playerAnimationTypes = ["run", "static", "jump", "armed_static", "armed_run", "armed_jump"] // Player's animations
  4. var playerAnimationsArray = [String]() // Array with all player Sprites
  5. var playerAnimationSpritesPrefix = "Player_"
  6. let runAnimationTime = 0.1
  7. var actualAnimation = [SKTexture]()
  8.  
  9. playerAtlas = SKTextureAtlas(named: "Player_anim")
  10.        
  11. for i in 0 ..< playerAtlas.textureNames.count {
  12.         playerAnimationsArray.append(playerAtlas.textureNames[i]) // Gets all the animations image names
  13.     }
  14.    
  15. for i in 0 ..< playerAnimationTypes.count {
  16.     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)
  17.  
  18.     for j in 0 ..< animations.count {
  19.                
  20.         if playerAnimation[playerAnimationTypes[i]] == nil {
  21.             playerAnimation[playerAnimationTypes[i]] = [] // Creates array if doesn't exist
  22.         }
  23.        
  24.         playerAnimation[playerAnimationTypes[i]]!.append(SKTexture(imageNamed: animations[j])) // Add texture to make the animation
  25.        
  26.     }
  27.    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement