Cocos2D學習筆記之Animation初始化
作者:佚名 
  本文介紹的是Cocos2D學習筆記之Animation初始化,主要通過兩個小實例來認識和學習Animation,來看內容。
 Cocos2D學習筆記之Animation初始化是本文要介紹的內容,主要來學習Animation,內容不多,汗很詳細,我們來看詳細內容,先來看Cocos2D中Animation的初始化的兩種方式:
(1).采用多張貼圖
- Animation walkAnimation = [Animation animationWithName:@"walk" delay:0.1f];
 - or(int i = 1; i < 5; i++)
 - {
 - [walkAnimation addFrameWithFilename:[NSString stringWithFormat:@"walk_%02d.png", i]];
 - }
 - id animate = [Animate actionWithAnimation:walkAnimation];
 - RepeatForever *rep = [RepeatForever actionWithAction:animate];
 - self runAction:rep];
 
(2).采用一張貼圖(動作幀序列)
- CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];
 - CCSprite* flight = [CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(0,0,31,30)];
 - flight.position = ccp(300, 0);
 - flight.scale = 1.1;
 - flight.anchorPoint = ccp(0.0f, 0.0f);
 - [mgr addChild:flight z:1 tag:99];
 - CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.2f];
 - for(int i = 0; i < 3; i++)
 - {
 - int x= i % 3;
 - [animation addFrameWithTexture:mgr.texture rect:CGRectMake(x*32, 0, 31, 30) ];
 - }
 - id action = [CCAnimate actionWithAnimation: animation];
 - [flight runAction:[CCRepeatForever actionWithAction:action]];
 
小結:Cocos2D學習筆記之Animation初始化的內容介紹完了,希望本文對你有所幫助!
責任編輯:zhaolei 
                    來源:
                    博客園
 














 
 
 
 
 
 
 