Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

srinivas.be88

macrumors newbie
Original poster
Aug 10, 2010
24
0
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
 
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)?
 
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.
 
The array representation in the file identified by aPath must contain only property list objects (NSString, NSData, NSArray, or NSDictionary objects).
 
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)?



thank you NickFalk..it is working nicely..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.