cocos2d - Replacing cached sprite image

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.

-------------Problems Reply------------

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.

Category:cocos2d iphone Views:1 Time:2012-02-21

Related post

  • Cocos2d: Scaling a sprite as it is being touched 2009-06-04

    I'm just wondering how I might do this and hoping that somebody has done something similar. I would like for a sprite to scale as the finger remains on the screen. Any tips, general guidelines, or methods I could look at would be appreciated. -------

  • Are there Adaptive Replacement Cache patent-free alternatives? 2009-12-10

    An open source high-performance project I'm working on needs to keep a cache of parsed/compiled files. A plain LRU or a plain LFU wouldn't fit. Plain LRU wouldn't work as there will be remote batch/spider processes hitting the service regularly. Plai

  • When To Refresh/Replace Cache in RSS Reader 2010-01-05

    For a simple rss reader, I am storing the results of queries in a client side (google gears) database. So, myapp.php?query=xyz is stored in one column, and the result xml is stored in the next column. Then, when myapp.php?query=xyz is requested, I fi

  • Cocos2D iPad Vector Sprites/Spritesheet creation 2010-06-24

    Is there a way to load vector graphics into the iPad using cocos(or some other method) as sprites or sprite sheets but leaving the images as vectors and not textures? The reason being is we have an animation that is just way way too big to load in as

  • Cocos2d - send the sprite image to a method 2011-03-03

    I have a method that splits a UIImage and returns the sections of the image as an array: - (NSMutableArray *) splitImage:(UIImage *)image; But I need to split a Cocos2d sprite in half. How can I get the UIImage from of the sprite? The closest thing I

  • cocos2d ccTouchesMoved moving sprite only to top right corner 2011-06-09

    Forgive my elementary question as I'm pretty new to cocos2d, but I'm having an issue moving a sprite around. The method seems to do what I long as it's moving in a positive x and positive y direction (top right corner). If I try to move it

  • Cocos2D Drag Drop Sprite Question 2011-09-12

    I am starting a simple game with Cocos2D. I have a few sprites that I can drag and drop using UIPanGestureRecognizer. The game will consist of draggin an image to a specific spot on the screen. Imagine a US State puzzle where you need to drag the ima

  • Cocos2d, moving a sprite using accelerometer in landscape bug with x axis when held upright 2011-10-19

    long time reader first time poster and so on. My problem is this, Currently i am moving a sprite around the screen of an iPod touch (landscape) using the accelerometer x and y values and cocos2d. The user can calibrate where the accelerometer zero po

  • Cocos2D - filling a sprite 2011-11-22

    UIImageViews have a property called contentMode that you can use as imageView.contentMode = UIViewContentModeScaleAspectFit; and it will fill the entire view with your image without distorting, even if it has to bleed the image to do that. Is there a

  • Objective-c Cocos2d moving a sprite 2011-11-24

    I hope someone knows how to do the following with cocos2d: I want a sprite to move but not in a single line by using [cocosGuy runAction: [CCMoveTo actionWithDuration:1 position:location]]; What I want is the sprite to do some kind of movements that

  • Cocos2d contentSize for sprite not working 2011-12-25

    I'm using cocos2d. After i load the ccspriteframecache and ccspritebatchnode, i made a ccsprite. But i need the contentsize of the sprite stage. However it returns 480.000000, 320.000000 instead, which the size of the whole screen. My image is a lot

  • How to debug Cocos2d removal of sprite memory issue 2012-03-06

    Have been working on a Tower Defense game for iOS for some time now. I am using Cocos2d (v0.99.5 not to sure). Recently started to get into some problems when I started remove sprites. Have profiles using instruments and Zombies and here's what I get

  • cache sprites to save the memory 2012-04-18

    in my games scene i use 5 background images(sprites) in CCParallaxNode and I have to use each sprite twice to move all this layers permanently. How can I cache this sprites to save the memory? I just want escape from CCSprite *for _level_1 and CCSpri

  • Cocos2d iPhone: Rotate Sprite using Accelerometer 2010-09-29

    I'm trying to rotate a sprite using the accelerometer. when I tilt right, I want him to rotate slightly to the right, and when I tilt left, I want him to rotate slightly to the left... Thanks in advance, Reed --------------Solutions------------- Firs

  • cocos2d hide/show sprites with animation 2010-10-26

    i am spending a lot for my time for a simple things i think.I want to hide and show a sprite in scene. myS = [CCSprite spriteWithFile:@"Background_Pause_pad.png"]; [myS setPosition:ccp(384,470)]; myS.opacity = 0; [self addChild:myS z:1]; and when i n

  • (cocos2d-iphone) Problem-Sprite rotates 180 degree to and fro 2010-11-12

    hi i have a problem with sprite during startup The problem is that the sprite rotates 180 degree to and fro once before setting to its position. It happens very fast. I know it is some bug but couldnt find the problem. Can anyone please help me. The

  • Cocos2d - CCMoveBy - finding sprite position 2012-01-27

    I'm using CCMoveBy in an action to shoot a projectile according to the direction of a Sneaky Joystick. I can't seem to get the position of the projectile DURING the action. I only get the starting positions of the projectile. CCMoveTo doesn't seem to

  • cocos2D replace scene not initializing the class 2012-02-03

    I have two scenes (mainMenu) and other (HelloWorldScene). I'm able to switch the scenes using replace scene but after trying to load it second time it doesn't call the init method. Here are my efforts so far. //In my mainMenu.m -(void)starting{ [[CCD

  • cocos2d getting a sprite to blink, it becomes invisible 2012-02-12

    im trying to make my sprite blink, but it just disappears, i have searched google, but i cant find a solution, heres what im doing: CCBlink * blinker = [CCBlink actionWithDuration: 0.5 blinks: 1]; [player runAction: blinker]; this method is called wh

Copyright (C), All Rights Reserved.

processed in 0.197 (s). 11 q(s)