Cocos2d-x How to make animation with CCRepeat
CCRepeat* Global::genAnimationFromImagesWithRepeat (CCArray* imageArray ,float delay) {
CCArray *animationFrames = CCArray::createWithCapacity(imageArray->count());
for (int i = 0; i < imageArray->count(); i++) {
CCString *file = (CCString*)imageArray->objectAtIndex(i);
CCSize size = Global::getImageSize(file->getCString());
int width = size.width;
int height = size.height;
animationFrames->addObject(Global::getFrameFromImage(file->getCString(),0 ,0 ,width ,height));
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animationFrames ,delay);
CCAnimate *animate = CCAnimate::create(animation);
CCRepeat *repeat = CCRepeat::create(animate,delay);
return repeat;
}
/* Create animation with CCRepeat */
CCRepeat* Global::genAnimationWithRepeat(const char* shadowName, float delay,float duration ,int nRow ,int nCol ,int lastNum) {
int rFrame,cFrame;
if(lastNum!=0) {
rFrame = nRow - 1;
cFrame = lastNum - 1;
} else {
rFrame = nRow ;
cFrame = nCol;
}
/* setting animation for sprite */
if(strlen(shadowName) > 0 ) {
CCSize size = Global::getImageSize(shadowName);
int width = size.width/nCol;
int height = size.height/nRow;
CCArray *animationFrames = CCArray::createWithCapacity(nRow*nCol);
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
animationFrames->addObject(Global::getFrameFromImage(shadowName,j,i ,width ,height));
if(lastNum > 0) {
if((i == nRow - 1) && (j == lastNum - 1)) break;
}
}
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animationFrames ,delay);
CCAnimate *animate = CCAnimate::create(animation);
CCRepeat *repeat = CCRepeat:: create(animate,duration);
return repeat;
}
return NULL;
}
CCArray *animationFrames = CCArray::createWithCapacity(imageArray->count());
for (int i = 0; i < imageArray->count(); i++) {
CCString *file = (CCString*)imageArray->objectAtIndex(i);
CCSize size = Global::getImageSize(file->getCString());
int width = size.width;
int height = size.height;
animationFrames->addObject(Global::getFrameFromImage(file->getCString(),0 ,0 ,width ,height));
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animationFrames ,delay);
CCAnimate *animate = CCAnimate::create(animation);
CCRepeat *repeat = CCRepeat::create(animate,delay);
return repeat;
}
/* Create animation with CCRepeat */
CCRepeat* Global::genAnimationWithRepeat(const char* shadowName, float delay,float duration ,int nRow ,int nCol ,int lastNum) {
int rFrame,cFrame;
if(lastNum!=0) {
rFrame = nRow - 1;
cFrame = lastNum - 1;
} else {
rFrame = nRow ;
cFrame = nCol;
}
/* setting animation for sprite */
if(strlen(shadowName) > 0 ) {
CCSize size = Global::getImageSize(shadowName);
int width = size.width/nCol;
int height = size.height/nRow;
CCArray *animationFrames = CCArray::createWithCapacity(nRow*nCol);
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
animationFrames->addObject(Global::getFrameFromImage(shadowName,j,i ,width ,height));
if(lastNum > 0) {
if((i == nRow - 1) && (j == lastNum - 1)) break;
}
}
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animationFrames ,delay);
CCAnimate *animate = CCAnimate::create(animation);
CCRepeat *repeat = CCRepeat:: create(animate,duration);
return repeat;
}
return NULL;
}
Comments
Post a Comment