0
votes

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?

1
Welcome to Stackoverflow! It would probably make it easier for others to help you, if you posted some of the code that you have already written.helmbert
thanks for the advice! I've edited the question...I think that the problem can't be in the code because using the same code and changing the image name with a default image or others it works4Jacopo.R

1 Answers

3
votes

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.