Loops 如何在一组10幅图像中循环多次?
我在cocos2d中有一个代码块,它通过循环浏览一组10幅图像来创建背景,如下所示:Loops 如何在一组10幅图像中循环多次?,loops,cocos2d-iphone,Loops,Cocos2d Iphone,我在cocos2d中有一个代码块,它通过循环浏览一组10幅图像来创建背景,如下所示: - (void)addBackground{ CGSize winSize = [CCDirector sharedDirector].winSize; //Add images to batchNode float maxReach = 0; for (int imageNumber=1; imageNumber < 13; imageNumber++) {
- (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;
}
}
}
-(void)addBackground{
CGSize winSize=[CCDirector sharedDirector].winSize;
//将图像添加到批处理节点
float maxReach=0;
对于(int-imageNumber=1;imageNumber<13;imageNumber++){
CCLOG(@“将图像简介%d.png添加到简介动画。”,imageNumber);
if(UI\u USER\u INTERFACE\u IDIOM()==UIUserInterfaceIdiomPad){
CCSprite*背景=[CCSprite spriteWithFile:[NSString stringWithFormat:@“国家风景”部分%d-iPad.png,图像编号]];
background.position=ccp((winSize.width/2)+maxReach,winSize.height/2);
[self addChild:background z:0];
maxReach=maxReach+background.contentSize.width;
}否则{
CCSprite*背景=[CCSprite spriteWithFile:[NSString stringWithFormat:@“国家风景”部分%d.png,图像编号]];
background.position=ccp((winSize.width/2)+maxReach,winSize.height/2);
[self addChild:background z:0];
maxReach=maxReach+background.contentSize.width;
}
}
}
当然,它只循环一次。我想让它转3圈。我正在考虑将一个整数设置为0,在每个循环的末尾加上1,然后再次运行它,直到它达到3。这听起来是最好的方法吗?您可以使用嵌套FOR/WHILE循环将其重复3次
它应该很有效。我看不出使用它有任何问题。对于简单的东西,任何可行的方法都是最好的;)但这听起来有用吗?为什么不试试呢?对我来说,这听起来很合理。我确实这么做了,似乎很有效。但我似乎有一个图像被它的下一个兄弟姐妹呈现和截断。它是唯一的一个,因此在第一个周期的末尾,有一个大小相同的相应“洞”,图像在末尾被截断。不知道为什么?