Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.92 KB | None | 0 0
  1. var Astronaut = SKSpriteNode()
  2.    
  3.     var playerAtlas = SKTextureAtlas()
  4.    
  5.     var playerAnimationsArray = [String]() // Array with all player Sprites
  6.     var playerAnimation = [String : [SKTexture]]()
  7.     let playerAnimationTypes = ["run", "static"] // Player's animations
  8.    
  9.     let playerScale = CGFloat(1.7)
  10.     let playerDirection = CGFloat(-1)
  11.    
  12.     override func didMoveToView(view: SKView) {
  13.         /* Setup your scene here */
  14.        
  15.         playerAtlas = SKTextureAtlas(named: "Player_anim")
  16.        
  17.         for i in 0 ..< playerAtlas.textureNames.count {
  18.             playerAnimationsArray.append(playerAtlas.textureNames[i])
  19.         }
  20.        
  21.         for i in 0 ..< playerAnimationTypes.count {
  22.             let numberOfAnimations = playerAnimationsArray.filter{$0.hasPrefix("player_\(playerAnimationTypes[i])")}.count
  23.             for j in 0 ..< numberOfAnimations {
  24.                 playerAnimation[playerAnimationTypes[i]]![j] = SKTexture(imageNamed: "player_\(playerAnimationTypes[i])\(String(j))")
  25.             }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement