Cocos2D Study Notes-Animation Initialization

Source: Internet
Author: User

Cocos2DStudy NotesAnimationInitialization is the content to be introduced in this article.AnimationThe content is not much. Khan is very detailed. Let's take a look at the details first.Cocos2DMediumAnimationTwo Methods of initialization:

(1). Use multiple textures

 
 
  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). Use a texture (action frame sequence)

 
 
  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]];  

Summary:Cocos2DStudy NotesAnimationThe initialization is complete. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.