cocos2d debugging question - cocos2d-iphone

The app keeps crashing, and I'm not able to make any sense out of the debugging messages. I'm sorry if this isn't enough information, but the smallest hint will be a big help to me! :D
2011-08-01 17:57:56.827 SpaceViking[1548:207] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-08-01 17:57:56.827 SpaceViking[1548:207] cocos2d: Couldn't add image:fps_images.png in CCTextureCache
2011-08-01 17:57:56.828 SpaceViking[1548:207] cocos2d: Could not open file: fps_images.png
2011-08-01 17:57:56.830 SpaceViking[1548:207] cocos2d: Could not initialize CCAtlasNode. Invalid Texture
2011-08-01 17:57:56.830 SpaceViking[1548:207] Retina Display Not supported
[Switching to process 1548 thread 0x207]
2011-08-01 17:57:56.946 SpaceViking[1548:207] GameObject init
2011-08-01 17:57:56.947 SpaceViking[1548:207] cocos2d: CCSpriteFrameCache: Frame '(null)15.png' not found
2011-08-01 17:57:56.950 SpaceViking[1548:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'

Looks like you are loading an image dynamically that does not exist, the final crash is because NSMutableArray does not allow nil values. Looks like you are appending something to your images for the loading since the image name is '(null)15.png', therefore you need to verify that the prefix you are appending is correct.

(null)15.png
I'm betting you're getting this because you aren't initializing an NSString properly.
NSString *myString;
myString = [NSString stringWithFormat:#"%#%#", myString, #"15.png"];
something like this... your string will default to "nil" until you set it to #""

Related

Error adding sprites using addchild method: argument must to be non-nil

I've a problem using the method addchild adding sprites
previously I've never had this problem and I could add png files without problems,now sometimes if I try to add some sprites to the scene using the addchild method I receive these errors:
[2126:15503] cocos2d: CCTexture2D. Can't create Texture. cgImage is nil
[2126:15503] cocos2d: Couldn't add image:image_1.png in CCTextureCache
[2126:15503] * Assertion failure in -[HelloWorldLayer addChild:]
I think that the problem isn't in the code because if I try to add sprites using the images included in the default Cocos2d project it works... I receive this error only from some images...also if I've added it by the same way to the project and to the scene, what could be the cause?
I receive this error also using the default helloWorldLayer class, without changing anything, only adding
CCSprite * sprite = [CCSprite SpriteWithFile: #"image_1.png"];
[self addChild:sprite];
the rest of the code is exactly the same of the default HelloWorldLayer class
there could be something that might cause this error in some png files?
Add image_1.png to your Xcode project. Make sure you use the exact same filename, for example Image_1.PNG won't load on devices due to uppercasing.

Having trouble to change different sprite sheet on cocos2d

I am trying to change a different sprite sheet on my cocos2d project.
And i was using spriteSheet.plist and it was working fine. For some reason, I need to add more sprite and change the file to spriteSheet2.plist
And i already include files like spriteSheet2.plist, spriteSheet2.pvr.ccz
But it ends up return a error msg
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id'
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
// [frameCache addSpriteFramesWithFile:#"spriteSheet.plist" ];
[frameCache addSpriteFramesWithFile:#"spriteSheet2.plist" ];
and other issue if i remove my original 'spritesheet.plist' from Xcode. Sprits is still working on the screen.
would anyone tell what should I do to get ride of the error message?
you have a batch node somewhere which was created with the first texture, to which you are trying to add sprites from the second texture. All sprites contained in a batch node must be from the same texture as the texture with which the batch node was created.

How do I load a CCSpriteBatchNode from the documents directory?

I have a file in the documents directory that I verify does exist before I call this method:
CCSpriteBatchNode *batchNode = [[CCSpriteBatchNode alloc] initWithFile:filePath capacity:9];
The error reported is:
-[CCFileUtils fullPathFromRelativePath:resolutionType:] : cocos2d: Warning: File not found: decompressed_file.png
cocos2d: CCTexture3d: Can't create Texture. cgImage is nil;
Using Cocos2d 2.0
You can use CCSpriteBatchNode and pull files from the Documents directory (or any other directory you want) by setting the searchPath, e.g. like so:
NSString *documentDirectory = aDirectory;
NSMutableArray * loadSearchPath = [[CCFileUtils sharedFileUtils].searchPath mutableCopy];
[loadSearchPath addObject:documentDirectory];
[CCFileUtils sharedFileUtils].searchPath = [loadSearchPath copy];
This adds aDirectory to the searchable paths where Cocos2D will be looking for the file with the name you specify in [CCSpriteBatchNode batchNodeWithFile:#"aFile"];
The cocos2d functions file methods assume you are loading from your bundle resources. I do not think you can load the file directly but what you can do is load it into a UIImage and then create a CCTexture2D with a CGImage. With your CCTexture2D you can create a CCSpriteBatchNode.
UIImage *img = [UIImage imageWithContentsOfFile:filePath];
CCTexture2d *tex = [[CCTextureCache sharedTextureCache] addCGImage:[img CGImage] forKey:#"myTexture"];
CCSpriteBatchNode *batch = [CCSpriteBatchNode batchNodeWithTexture:tex capacity:9];
These steps are whats going on in the background anyway when you create a CCSpriteBatchNode using the normal methods. Except for the bundle assumption.
If you are making the sprite batch node more than once for some reason, you can check if the texture already exists in the cache before reloading the UIImage.

Cocos2D: Best way to display text from font atlas?

Based on the use CCDirector makes of CCLabelAtlas, I tried the following:
scoreLabel = [[CCLabelAtlas alloc] initWithString:#"0123456789" charMapFile:#"fps_images.png" itemWidth:8 itemHeight:12 startCharMap:'.'];
[scoreLabel setPosition:ccp(200, 200)];
[self addChild:scoreLabel];
I must be missing something as nothing displays. I'm using the basic .png that's supplied with Cocos2D.
What am I missing? Thanks!

Proper implementation of Particle Designer plist emitters in cocos2d?

I'm confused about how to properly use emitters made in Particle Designer with Retina displays in cocos2d. I have tried using an emitter with a non-hd texture (fire.png for example) saved as "particle.plist" with and without the texture embedded and I get a warning of some kind either way. I then made another emitter with fire-hd.png and the name "particle-hd.plist", and I get the same types of warnings, stuff like, cocos2d: Filename(fire-hd.png) contains -hd suffix. Removing it. See cocos2d issue #1040
Searching for issue #1040 yields a little info, but not enough for me to fix this.
A little enlightenment?
You need to prepare these files.
particle.plist (it uses texture 'fire.png' with or without the texture embedded)
fire-hd.png
CCParticleSystem searches -hd texture file first, then non-hd texture file, and then embedded texture data.
hd / retina partcle systems
EDIT
"Warning HD file not found" for Particle plist is false warning. You can use CCParticleSystem initWithDictionary method without any warning in this case.
NSString *path = [[NSBundle mainBundle]
pathForResource:#"particle1_traile" ofType:#"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
CCParticleSystem *particle = [[[CCParticleSystemQuad alloc]
initWithDictionary:dict] autorelease];