2013-03-23 43 views
-1

我在cocos2d的代碼塊通過一組10張圖像的循環,像這樣創建了一個背景:如何多次循環播放一組10幅圖像?

- (void)addBackground{ 
    CGSize winSize = [CCDirector sharedDirector].winSize; 

    //Add images to batchNode 
    float maxReach = 0; 
    for (int imageNumber=1; imageNumber < 13; imageNumber++) { 
     CCLOG(@"Adding image intro%d.png to the introAnimation.",imageNumber); 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
      CCSprite *background = [CCSprite spriteWithFile:[NSString stringWithFormat:@"national_scenery_part%d-iPad.png",imageNumber]]; 
      background.position = ccp((winSize.width/2)+maxReach, winSize.height/2); 
      [self addChild:background z:0]; 
      maxReach = maxReach + background.contentSize.width; 
     } else { 
      CCSprite *background = [CCSprite spriteWithFile:[NSString stringWithFormat:@"national_scenery_part%d.png",imageNumber]]; 
      background.position = ccp((winSize.width/2)+maxReach, winSize.height/2); 
      [self addChild:background z:0]; 
      maxReach = maxReach + background.contentSize.width; 
     } 
    } 
} 

但是,當然,它只是循環一次。我希望它循環3次。我正在考慮將整數設置爲0,並在每個循環的末尾添加1,然後再次運行,直到達到3.這聽起來像是最好的方法嗎?

+1

對於那些簡單的任何方式,工作是最好的;) – LearnCocos2D 2013-03-24 00:06:58

+0

但它聽起來像這樣會工作? – marciokoko 2013-03-24 01:29:49

+0

爲什麼不嘗試呢?聽起來對我來說比合理。 – LearnCocos2D 2013-03-24 19:28:39

回答

0

您可以使用嵌套的FOR/WHILE循環重複3次。

它應該很好。我沒有看到使用此問題的任何問題。