Cocos2D學習筆記之Animation初始化

來源:互聯網
上載者:User

Cocos2D學習筆記之Animation初始化是本文要介紹的內容,主要來學習Animation,內容不多,汗很詳細,我們來看詳細內容,先來看Cocos2DAnimation的初始化的兩種方式:

(1).採用多張貼圖

 
  1. Animation walkAnimation = [Animation animationWithName:@"walk" delay:0.1f];    
  2. or(int i = 1; i < 5; i++)    
  3. {    
  4.  [walkAnimation addFrameWithFilename:[NSString stringWithFormat:@"walk_%02d.png", i]];    
  5. }    
  6. id animate = [Animate actionWithAnimation:walkAnimation];    
  7. RepeatForever *rep = [RepeatForever actionWithAction:animate];    
  8.      
  9. self runAction:rep];  

(2).採用一張貼圖(動作幀序列)

 
  1. CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];    
  2.  CCSprite* flight = [CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(0,0,31,30)];    
  3.  flight.position = ccp(300, 0);    
  4.  flight.scale = 1.1;    
  5.  flight.anchorPoint = ccp(0.0f, 0.0f);    
  6.  [mgr addChild:flight z:1 tag:99];    
  7.             
  8.  CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.2f];    
  9.  for(int i = 0; i < 3; i++)     
  10.  {    
  11.     int x= i % 3;    
  12.     [animation addFrameWithTexture:mgr.texture rect:CGRectMake(x*32, 0, 31, 30) ];    
  13.  }    
  14.  id action = [CCAnimate actionWithAnimation: animation];    
  15. [flight runAction:[CCRepeatForever actionWithAction:action]];  

小結:Cocos2D學習筆記之Animation初始化的內容介紹完了,希望本文對你有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.