how to display the images from the NSMutableArray

Discussion in 'iOS Programming' started by srinivas.be88, Aug 31, 2010.

  1. srinivas.be88 macrumors newbie

    Joined:
    Aug 10, 2010
    #1
    hi,
    i want to display 5images based on the level . for example there are 5 images named image1.png,image2.png...image5.png.when the level value set to 3 need to display 3 images on the screen. so i used NSMutableArray to create CCSprite object . now how to display that images.

    Code:
    int i,endvalue=3;
    	NSMutableArray *levelStar = [ [NSMutableArray alloc] initWithCapacity:9 ];
    	for(i=1;i<=endvalue;i++)
    	{
    		CCSprite *star = [CCSprite spriteWithFile:@"image"+i+".png"];
    		star.position = ccp( 80+(i*10),60+(i*10));
    		[levelStar addObject:star];
    		[self addChild:star];
    }

    pleae help me
     
  2. NickFalk macrumors 6502

    NickFalk

    Joined:
    Jun 9, 2004
    #2
    Code:
    int i,endvalue=3;
    NSMutableArray *levelStar    =  [ [NSMutableArray alloc] initWithCapacity:9 ];
    for(i=1; i <= endvalue; i++)
    {
    NSString *fileName   =   [NSString stringWithFormat:@"image%i.png", i];
    CCSprite *star   =   [CCSprite spriteWithFile: filename];
    star.position   =   ccp( 80+(i*10),60+(i*10));
    [levelStar addObject: star];
    [self addChild: star];
    }
    
    Also: Why using a mutable Array if you already know the capacity (which you don't use to its full extent in the above code I might add)?
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    And why use CCSprite when UIImage would probably do?
     
  4. ranguvar macrumors 6502

    Joined:
    Sep 18, 2009
    #4
    If you come on this board to ask for advice, please take it! Your various threads demonstrate that you're not ready to write code. Please check out the "I want to learn Objective-C" threads to find out about good books and tutorials about Cocoa(-Touch) and Objective-C.
     
  5. sherry2009 macrumors newbie

    sherry2009

    Joined:
    Dec 14, 2009
    #5
    The array representation in the file identified by aPath must contain only property list objects (NSString, NSData, NSArray, or NSDictionary objects).
     
  6. srinivas.be88 thread starter macrumors newbie

    Joined:
    Aug 10, 2010
    #6


    thank you NickFalk..it is working nicely..
     

Share This Page