[笔记]Cocoa训练营-cocos2d游戏编程篇-动画

来源:互联网 发布:js 数组由小到大排序 编辑:程序博客网 时间:2024/06/03 07:42

cocos2d 1.0及其以上版本

游戏动画随笔;

 

 1 -(id)init 2 { 3     self=[super init]; 4     if (self) { 5         CCSprite *sp=[CCSprite spriteWithFile:@"Space.png"]; 6         sp.anchorPoint=CGPointZero; 7         sp.opacity=100; 8         [self addChild:sp z:0 tag:1]; 9         //分数10         CCLabelBMFont *lbScore=[CCLabelBMFont labelWithString:@"Time : 0" fntFile:@"font09.fnt"];11         lbScore.anchorPoint=ccp(1, 1);12         lbScore.scale=0.6;13         lbScore.position=ccp(310, 450);14         [self  addChild:lbScore z:1 tag:3];15         //载入图像集16         CCSpriteBatchNode *mgr=[CCSpriteBatchNode batchNodeWithFile:@"flight.png" capacity:5];17         [self addChild:mgr z:0 tag:4];18         CCSprite *spriter=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(0, 0, 31, 30)];19         [mgr addChild:spriter z:1 tag:5];20         spriter.scale=1.1;21         spriter.anchorPoint=ccp(0, 1);22         spriter.position=ccp(10, 410);23        24         25         CCLabelBMFont *lbLife=[CCLabelBMFont labelWithString:@"3" fntFile:@"font09.fnt"];26         lbLife.anchorPoint=ccp(0.0, 0.l);27         lbLife.scale=0.6;28         [self addChild:lbLife z:1 tag:6];29         lbLife.position=ccp(50, 400);30         //单一的飞机  取31,30 坐标之图片31         flight=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(0, 0, 31, 30)];32         flight.anchorPoint=ccp(0, 1);33         flight.scale=1.6;34         flight.position=ccp(160, 40);35         [self addChild:flight z:1 tag:99];36         /动画部分代码**************************************************
      *************************************************************/
37 CCSpriteFrame *frame=[CCSpriteFrame frameWithTexture:mgr.texture rect:CGRectMake(0, 0,31,30)];38 NSArray *array=[[NSArray alloc]initWithObjects:frame, nil];39 //动画40 CCAnimation *animation2=[CCAnimation animationWithSpriteFrames:array delay:0.2f];41 //动画42 for (int i=0; i!=3; i++) {43 int x=i%3;44 [animation2 addSpriteFrameWithTexture:mgr.texture rect:CGRectMake(x*32, 0, 31, 30)];45 }46 //动作47 id action=[CCAnimate actionWithAnimation:animation2];48 //循环49 [flight runAction:[CCRepeatForever actionWithAction:action]];50     /*****************************************************************/51 // self.isTouchEnabled=YES;52 53 }54 return self;55 }
原创粉丝点击