// Obtain the shared instance of the cache
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache;
// load the frames
[cache addSpriteFramesWithFile:@"frames.plist"];
// It loads the frame named "frame1.png".
// IMPORTANT: It doesn't load the image "frame1.png". "frama1.png" is a just the name of the frame
CCSpriteFrame *frame = [cache spriteFrameByName:@"frame1.png"];
[sprite setDisplayFrame:frame];
一个已经存在的CCSprite怎么替换新的图片
-(void) setTexture:(CCTexture2D*)texture
例子如下:
CCSprite * headSprite=[CCSprite spriteWithFile:@"avatar_hall.png"]; UIImage * image=[UIImage imageNamed:@"avatar_hall2.png"]; CCTexture2D * newTexture=[[CCTextureCache sharedTextureCache] addCGImage:image.CGImage forKey:nil]; [headSprite setTexture:newTexture];