【发布时间】:2011-07-21 23:19:13
【问题描述】:
当我在循环中为精灵表设置动画时,我不知道有多少精灵,所以我必须先计算它们,因为当动画完成后,我必须运行其他东西。
那么我如何计算开始循环之前的图像数量? 还是有另一种方法? (这个函数可以获得各种精灵表。 我现在更喜欢不使用 Plist。
非常感谢。
-(void)animation
{
WeInAction=1;
//animation
CCSpriteBatchNode *spriteSheet = [ CCSpriteBatchNode batchNodeWithFile:animation];
[self addChild:spriteSheet];
CCSprite *dollSprite = [CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(0, 0, 320, 350)];
[spriteSheet addChild:dollSprite];
spriteSheet.anchorPoint=CGPointMake(0, 30);
CGSize s = [[CCDirector sharedDirector] winSize];
dollSprite.position = ccp(s.width/2,s.height/2);
CCAnimation *dollAnimation = [CCAnimation animation];
[dollAnimation setDelay:0.1f];
int frameCount = 0;
for (int y = 0; y < 5; y++) //cocos add all this frames to memery and then he starts down the action,
{
for (int x = 0; x < 6; x++)
{
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:spriteSheet.texture rect:CGRectMake(x*320,y*350,320,350)];
[dollAnimation addFrame:frame];
frameCount++;
if (frameCount == 25)
break;
}
}
CCAnimate *Action = [CCAnimate actionWithAnimation:dollAnimation];
id call=[CCCallFunc actionWithTarget:self selector:@selector(finishAnimation)];
id sequence=[CCSequence actions:Action,[CCHide action],call,nil];
[dollSprite runAction:sequence];
NSLog(@"%@",basic_pic);
}
【问题讨论】:
标签: objective-c cocos2d-iphone