views:

72

answers:

2

Basically i have an array of Sprites to be loaded and removed one by one in an order. I have a list of animal names in an array like

 const NSString *Animal1[30] = {@"Lion .png",@"Zebra .png",...........

To load a sprite i use the following code

image[i]= [Sprite spriteWithFile: [NSString stringWithFormat:@"%@",Animal1[i]]];
image[i].position = ccp( 240,180 );
[self addChild: image[i]];

Then to remove the sprite after use I use the following code

[self removeChild:image[i] cleanup:YES];

What happens when i run the code in simulator is the sprite loads one after other till 20th animal. After the 20th animals the application crashes. I dont know what is the problem.If i have the array less than 20 it works fine but when it exceed the application crashes. Can anyone plz help to resolve the issue.

A: 

If it works for the first 20, it sounds like you may have a bad image or an erroneous filename for that 21st image. If you try to create a sprite from an unsupported or nonexistent image, then you'll get a crash.

Check and make sure all the filenames listed are actually inside your package (check case, too, since they're case sensitive!). Make sure the filenames match exactly - in the code sample you pasted above, it looks like there are spaces in the titles.

If the files are all there, make sure you didn't save one of them as a Photoshop document instead of as a .png or something. Even if the filename ends in .png, it doesn't mean that it was saved in that format.

cc
Thanx very much for the reply.I checked every single image for extension,case,location but still it crashes.I even changed the image set but still it crashes after 20th image.
Muniraj
Can you post more of your code, then? Show us the whole code block.
cc
A: 

From your description of the problem it could even be a bad index and you're just incrementing out of bounds or something. The best way to clear it up is to do some basic debugging.

  1. place the last item in the middle of the array. Does it still blow up on the last one or on the same entry no mater what position it's in?
  2. remove the offending item to see if the code works without it
  3. trace thru the code and see the entry point where it's blowing up, check your stack trace, etc.
jtalarico
Hi thanx for the replyI tried replacing the item and removing it but still it didnt work.
Muniraj