01
//使用 plist 的动画
02
CCSpriteFrameCache *sfcache = CCSpriteFrameCache::sharedSpriteFrameCache();
03
sfcache->addSpriteFramesWithFile("yy/yy.plist");
04
05
CCMutableArray *anim_frames_go = new CCMutableArray();
06
char tmp[50];
07
for (int j = 0; j < 5; j++)
08
{
09
sprintf(tmp, "yy_%d.png", j);
10
CCSpriteFrame *frame = sfcache->spriteFrameByName(tmp);
11
anim_frames_go->addObject(frame);
12
}
13
CCAnimation *animation_go = CCAnimation::animationWithFrames(anim_frames_go, 0.2f);
14
anim_frames_go->release();
15
CCAnimate animate_go = CCAnimate::actionWithAnimation(animation_go, true);
16
sprite->runAction(CCRepeatForever::actionWithAction(animate_go));
17
18
19
//不使用 plist 的
20
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("yy/yy.png");
21
CCSpriteFrame *frame0 = CCSpriteFrame::frameWithTexture(texture, CCRectMake(112*0, 64*0, 112, 64));
22
CCSpriteFrame *frame1 = CCSpriteFrame::frameWithTexture(texture, CCRectMake(112*1, 64*0, 112, 64));
23
CCSpriteFrame *frame2 = CCSpriteFrame::frameWithTexture(texture, CCRectMake(112*0, 64*1, 112, 64));
24
CCSpriteFrame *frame3 = CCSpriteFrame::frameWithTexture(texture, CCRectMake(112*1, 64*1, 112, 64));
25
CCSpriteFrame *frame4 = CCSpriteFrame::frameWithTexture(texture, CCRectMake(112*0, 64*2, 112, 64));
26
27
CCMutableArray *anim_frames_go = new CCMutableArray(5);
28
anim_frames_go->addObject(frame0);
29
anim_frames_go->addObject(frame1);
30
anim_frames_go->addObject(frame2);
31
anim_frames_go->addObject(frame3);
32
anim_frames_go->addObject(frame4);
33
34
CCAnimation *animation_go = CCAnimation::animationWithFrames(anim_frames_go, 0.2f);
35
anim_frames_go->release();
36
37
CCAnimate *animate_go = CCAnimate::actionWithAnimation(animation_go, true);
38
msprite->setDisplayFrame(frame0);
39
sprite->runAction(CCRepeatForever::actionWithAction(animate_go));
原文地址:
http://my.oschina.net/yunyu/blog/62862