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
- 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). Use a texture (action frame sequence)
- 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]];
Summary:Cocos2DStudy NotesAnimationThe initialization is complete. I hope this article will help you!