IOS Cocos2d How to gen animation with CCRepeatForever
+ (CCRepeatForever*) genAnimation:(NSString*) shadowName delay:(float) delay _nRow:(int) nRow _nCol:(int) nCol lastNum:(int) num {
int rFrame,cFrame;
if(num!=0) {
rFrame = nRow - 1;
cFrame = num - 1;
} else {
rFrame = nRow ;
cFrame = nCol;
}
/* setting animation for sprite */
if([shadowName length] > 0 ) {
CGSize size = [Global getImageSize:shadowName];
int width = size.width/nCol;
int height = size.height/nRow;
NSMutableArray *animationFrames = [NSMutableArray arrayWithCapacity:nRow*nCol];
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
[animationFrames addObject:[self getFrameFromImage:shadowName x:j y:i w:width h:height]];
if(num > 0) {
if((i == nRow - 1) && (j == num - 1)) break;
}
}
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animationFrames delay:delay];
CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animate];
return repeat;
}
return nil;
}
// Gen animation from list image
+ (CCRepeatForever*) genAnimationFromImages:(NSMutableArray*) imageArray delay:(float) delay {
/* setting animation for sprite */
NSMutableArray *animationFrames = [NSMutableArray arrayWithCapacity:[imageArray count]];
for (int i = 0; i < [imageArray count]; i++) {
CGSize size = [Global getImageSize:(NSString*)[imageArray objectAtIndex:i]];
int width = size.width;
int height = size.height;
[animationFrames addObject:[self getFrameFromImage:(NSString*)[imageArray objectAtIndex:i] x:0 y:0 w:width h:height]];
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animationFrames delay:delay];
CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animate];
return repeat;
}
int rFrame,cFrame;
if(num!=0) {
rFrame = nRow - 1;
cFrame = num - 1;
} else {
rFrame = nRow ;
cFrame = nCol;
}
/* setting animation for sprite */
if([shadowName length] > 0 ) {
CGSize size = [Global getImageSize:shadowName];
int width = size.width/nCol;
int height = size.height/nRow;
NSMutableArray *animationFrames = [NSMutableArray arrayWithCapacity:nRow*nCol];
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
[animationFrames addObject:[self getFrameFromImage:shadowName x:j y:i w:width h:height]];
if(num > 0) {
if((i == nRow - 1) && (j == num - 1)) break;
}
}
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animationFrames delay:delay];
CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animate];
return repeat;
}
return nil;
}
// Gen animation from list image
+ (CCRepeatForever*) genAnimationFromImages:(NSMutableArray*) imageArray delay:(float) delay {
/* setting animation for sprite */
NSMutableArray *animationFrames = [NSMutableArray arrayWithCapacity:[imageArray count]];
for (int i = 0; i < [imageArray count]; i++) {
CGSize size = [Global getImageSize:(NSString*)[imageArray objectAtIndex:i]];
int width = size.width;
int height = size.height;
[animationFrames addObject:[self getFrameFromImage:(NSString*)[imageArray objectAtIndex:i] x:0 y:0 w:width h:height]];
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animationFrames delay:delay];
CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animate];
return repeat;
}
Comments
Post a Comment