當我在一個循環中創建一個精靈圖表時,我不知道有多少精靈在那裏,所以我必須先計算它們,因爲動畫完成後,我必須運行別的東西。計算精靈圖表中的圖片數量 - cocos2d
那麼我該如何計算一下開始循環的圖像數量? 還是有另一種方式呢? (此功能可以得到各種精靈表。 我現在寧願不使用的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);
}
我不能理解你。你可以解釋嗎 ?我正在用x和y運行一個循環,而之前我不知道它們的值。有一種方法可以知道嗎?我需要運行一個通用循環,以適應任何spritesheet它.. – Curnelious
Cocos2D不檢查圖像。 Cocos2D只知道Spritesheet中有多個圖像,如果你告訴它有。實際上它不知道普通圖像和Spritesheet之間的區別,除非你告訴它。如果你的所有圖像總是相同的尺寸,那麼你可以自己計算它,或者你可以根據你插入的值創建一個計算方法。 –
我無法找到一種方法如何知道...你可以給我任何大方向?科科斯是「盲目的」,它運行在我給它的循環數... – Curnelious