2011-07-07 6 views
-1

次のコードを使用してスプライトを追加し、次に角を確認してください 交差これらのスプライトを別のものに置き換えたいです。 これらのランダムな画像を置き換えることによって私を助けてください。問題は、私はスプライトシートを使用して、これをやっているにも.........ランダム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; 
    } 

答えて

0

を を取られた画像を交換するということです。スプライトシートを作成してそのスプライトシートをCCSpriteBatchNodeのオブジェクトに割り当てることができる場合は、

$ CCSpriteBatchNod * m_meteoritesSprites = [CCSpriteBatchNode batchNodeWithFile:@ "Meteo.pvr.ccz"];

、その後、負荷のplist

$ [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@ "Meteo.plist"];その後、

$ m_meteoritesSprites = [CCSpriteBatchNode batchNodeWithFile: "Meteo.pvr.ccz" @]のようなあなたのスプライトにイメージを割り当てるためにスプライトフレームを使用します。

私はスプライトシート

はこれがあなたの役に立てば幸い作るためにTexrturePackerを使用。

関連する問題