两种播放帧动画的方法

 1 bool GameLayer::init()
 2 {
 3     CCFish* background = CCFish::create();
 4     this->addChild(background);
 5     
 6     //ccBezierConfig config;
 7     //config.controlPoint_1 = ccp(20,0);
 8     //config.controlPoint_2 = ccp(300,300);
 9     //config.endPosition = ccp(400,50);
10     //CCBezierTo* bezier = CCBezierTo::create(5,config);
11 
12     //CCPointArray* array = CCPointArray::create(10);
13     //array->addControlPoint(ccp(20,250));
14     //array->addControlPoint(ccp(400,250));
15     //array->addControlPoint(ccp(400,20));
16     //array->addControlPoint(ccp(300,220));
17     //array->addControlPoint(ccp(210,120));
18     //CCCardinalSplineTo* card = CCCardinalSplineTo::create(5,array,0);
19 
20     //帧动画效果实现:图片大小一样时
21     /*CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("run.png");
22     CCArray* array = CCArray::createWithCapacity(24);
23     int width = texture->getContentSize().width;
24     int height =texture->getContentSize().height;
25     int spriteWidth = width / 8;
26     int spriteHeight = height / 3;
27     for(int i = 1;i<3;i++)
28     {
29         for(int j = 0;j<8;j++)
30         {
31             CCSpriteFrame* spriteFrame = CCSpriteFrame::createWithTexture(texture,CCRectMake(spriteHeight * j,spriteWidth * i,spriteWidth,spriteHeight));
32             array->addObject(spriteFrame);
33         }
34     }
35     CCAnimation* animation = CCAnimation::createWithSpriteFrames(array,0.05f);
36     animation->setLoops(1000);
37     CCMoveTo* move = CCMoveTo::create(5,ccp(470,160));
38     CCAnimate* animate = CCAnimate::create(animation);
39     CCSpawn* spawn = CCSpawn::create(move,animate,NULL);
40     sprite->runAction(spawn);*/
41 
42     //图片大小不一致时
43     CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fish.plist");
44     CCSprite* sprite = CCSprite::create("fish.png");
45     this->addChild(sprite);
46     sprite->setFlipX(true);
47     sprite->setPosition(ccp(40,160));
48     CCAnimation* am = CCAnimation::create();
49     for(int i = 1;i<8;i++)
50     {
51         CCString * string = CCString::createWithFormat("fish03_%02d.png",i);
52         CCSpriteFrame* frame= CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(string->getCString());
53         am->addSpriteFrame(frame);
54     }
55     am->setDelayPerUnit(0.1/1);
56     am->setLoops(1000);
57     CCAnimate * at = CCAnimate::create(am);
58     sprite->runAction(at);
59     return true;
60 }

 

posted @ 2015-03-25 22:36  溈鉨wo乄菰単  阅读(297)  评论(0编辑  收藏  举报