I'm new to cocos2d. I've been following a tutorial which I've got working but when I updated the image I used to shoot fireballs by deleting and replacing it from the resources folder, the image no longer renders. What do I have to do when replacing an image?
Before I swapped the images:
CCSprite *projectile = [CCSprite spriteWithFile:@"Projectile.png" rect:CGRectMake(0, 0, 20, 20)];
After swapping images:
CCSprite *projectile = [CCSprite spriteWithFile:@"Fireball.png" rect:CGRectMake(0, 0, 20, 20)];
Do I need to delete the cache somehow and re-add the image?
I added this line below my code and it worked:
[projectile setTexture:[[CCTextureCache sharedTextureCache] addImage:@"Fireball.png"]];
Strange how I have to add a new line of code to replace an image.
I find that sometimes i need to clean and build for the updated texture to finally make it to the app's bundle ... (I suspect this happens when i change a resource while the app is running, but frankly i have lost too much time with this to investigate). Now i de-facto clean and build when changing resources.
I am not certain this is a 'cocos2d' discussion, but rather an Xcode one. The cocos2d texture cache is entirely constructed in memory, during the execution of your app. It is a mechanism that 1) helps keep the memory footprint smaller, and 2) also boosts performance since a texture file is only loaded once if you dont clear the cache. Xcode on the other hand keeps copies of all your files in multiple places. By 'cleaning' a build, you ensure that previous versions of files are removed, and all the current resources (including textures) are placed in the appropriate places for the development environment to function properly.