Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I load 15-20 sprites in Cocos2D at the same point (ccp(20,20), which is an alias for CGPointMake) using NSArray? This is what I'm doing now, and it doesn't work:

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( 20,20);
    [levelStar addObject:star];
    [self addChild:star];
}
share|improve this question
    
Please edit your previous question instead of asking a new one. Thank you. –  thedaian Nov 8 '11 at 15:21
1  
-1. Put some effort into that question, so that it's actually answerable. You don't tell us what doesn't work. We don't know if these files you try to load are actually there and in the title you write about 20 sprites and then in your question it's suddenly 15 sprites? –  bummzack Nov 8 '11 at 15:31
    
leave the count place the 15 or 20 sprite image in the same ccp point just need that then i will ask the further things later –  ceacare Nov 8 '11 at 15:34
    
if you dont no to answer dont downvote it, it doesnt make sense,if you know answer post it otherwise dont discourage it –  ceacare Nov 8 '11 at 15:35
1  
I agree with bummzack, both of your questions on this subject are very underspecified: it isn't clear what you want, and what is going wrong. I would suggest you check out this excellent article on asking good questions as well as this more recent piece on explaining the research effort you've already put forth. –  Josh Petrie Nov 8 '11 at 15:58

1 Answer 1

While it is extremely unclear what you are doing and what you are considering behavior that "doesn't work," I want to point out that there is a huge discrepancy with your question (which asked about setting up 15 to 20 sprites) and your code, which may be the root of your troubles. Specifically, you have this loop:

int i, endvalue=3;
for(i = 1; i <= endvalue; i++) {
  ....
}

This loop only executes three times. So you're only setting up and adding three sprites to the array total. Perhaps you meant to write your loop this way?

for(int i = 0; i < 15; ++i) {
  ...
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.