• [笔记]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 }
  • 相关阅读:
    Java读写锁(ReentrantReadWriteLock)学习
    水平拆分和垂直拆分理解(未完)
    MySQL 主从复制
    sharding-JDBC 实现读写分离
    Linux查看程序端口占用情况
    sharding-jdbc 实现分表
    MySQL explain
    MySQL的七种join
    MySQL建立高性能索引策略
    Nginx企业级优化
  • 原文地址:https://www.cnblogs.com/tubufeng/p/2674375.html
Copyright © 2020-2023  润新知