我已經添加了一些sprite通過使用下面的代碼,然後通過檢查矩形 交集我想用另一個替換這些精靈。可以通過提供代碼 替代這些隨機圖像幫助我。問題是,要被替換的圖像也採取 隨機.........iphone中的圖片替換
yp = 40;
//CCSprite *spr;
movableSprites = [[NSMutableArray alloc] init];
for(int m=0; m<4; m++)
{
do
{
i = 'a';
//NSLog(@"valueeeeeeeee %d",i);
next = arc4random()%maxalphabets;
//NSLog(@"valueeeeeeeeenexttttt %d",next);
i+=next;
//NSLog(@"valueeeeeeeee %d",i);
spr = (CCSprite*)[self getChildByTag:i];//checks if found alreadyyyyyy
NSLog(@"Strrrrrrrr is:%@",spr);
}while(spr);
spNameStr = [NSString stringWithFormat:@"%c3.png",i];
NSLog(@"tagggg %d",i);
NSLog(@"spNameStr is:%@",spNameStr);
spr = [CCSprite spriteWithFile:spNameStr ];
spr.tag = i;
//NSLog(@"tagiiiiii %d",i);
spr.position = ccp(60,yp);
[self addChild:spr z:2];
[movableSprites addObject:spr];
yp+=spr.contentSize.height+35;
}
yp = 40;
NSMutableArray *answerimagesCopy = [NSMutableArray arrayWithArray:movableSprites];
NSLog(@"answer image copy elements areeeee %@",answerimagesCopy);
for(k = 0; k < movableSprites.count; ++k)
{
NSLog(@"inside forrrr");
int j=arc4random()%([answerimagesCopy count]);
NSLog(@"valueee of jjjjjjjj %d",j);
CCSprite *ansimage = [answerimagesCopy objectAtIndex:j];
//NSLog(@"................ %@",ansimage);
p=ansimage.tag;
NSLog(@"tagg..... %d",p);
[answerimagesCopy removeObjectAtIndex:j];
//NSLog(@"tagg..... %d",j);
spNameStr = [NSString stringWithFormat:@"%c4.png",p];
NSLog(@"spNameStr is:%@",spNameStr);
//NSLog(@"tagggg %d",j);
spr = [CCSprite spriteWithFile:spNameStr ];
spr.tag = p+100;
spr.position = ccp(260,yp);
[self addChild:spr z:1];
yp+=spr.contentSize.height+35;
}