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


    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 }
  • 相关阅读:
    补习系列(4)-springboot 参数校验详解
    华为鲁勇:5G+云+AI三大核心引擎将驱动广州数字经济发展
    selenium firefox
    徐翔之后新生代“敢死队”浮出水面:八年一万倍
    ActiveMQ讯息传送机制以及ACK机制
    一元线性回归分析及java实现
    jsoup -- xml文档解析
    HDU 1020 Encoding 字符串
    PHP缓存之文件缓存
    Eclipse PHPEclipse 配置
  • 原文地址:https://www.cnblogs.com/tubufeng/p/2674375.html
Copyright © 2020-2023  润新知