19,468
社区成员
发帖
与我相关
我的任务
分享
int n=0;
CCTexture2D *pRunImage=CCTextureCache::sharedTextureCache()->addImage("run.png");
CCSpriteFrame *pRun[24]; //图片一共24张
for (int i=0;i<3;i++) //行循环
{
for (int j=0;j<8;j++) //列循环,将图片保存在帧中
{
//每张图片大小为64×64
pRun[n]=CCSpriteFrame::create("run.png",CCRectMake(j*64,i*64,64,64));
n++;
}
}
CCArray *pArr=CCArray::createWithCapacity(24);
for (int i=0;i<24;i++)
{
pArr->addObject(pRun[i]);
}
CCAnimation *pRunAnimation=CCAnimation::createWithSpriteFrames(pArr,0.05f);
CC_BREAK_IF(!pRunAnimation);
CCSprite *pSakuya=CCSprite::create("run.png",CCRectMake(0,0,64,64));//精灵第一帧
CC_BREAK_IF(!pSakuya);
pSakuya->setPosition(ccp(100,200));
this->addChild(pSakuya,2);
CCAnimate *pRunDouga=CCAnimate::actionWithAnimation(pRunAnimation);
CC_BREAK_IF(!pRunDouga);
pSakuya->runAction(CCRepeatForever::create(pRunDouga)); //无限循环播放