cocos2d - Changing the image of a CCSprite

CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"new_image_name"];
[spriteWant2Change setTexture: tex];

what to do if texture is different in size from previous one ?

If the sprites are of different size then you will need to do this after calling setTexture function 

[spriteWant2Change setTextureRect:CGRectMake(0, 0, tex.contentSize.width, tex.contentSize.height)];

摘自:Stack Overflow

posted @ 2013-12-05 16:47  有妄想症的猫zz  阅读(315)  评论(0编辑  收藏  举报