How do I change a CCSprite's Dimensions after changing texture?
cocos2d-iphone
Solution
Try this:
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:@"Circle.png"];
if (texture)
{
// Get the size of the new texture:
CGSize size = [texture contentSize];
[sprite setTexture:texture];
// use the size of the new texture:
[sprite setTextureRect:CGRectMake(0.0f, 0.0f, size.width,size.height)];
}
Problem
I have a piece of code in my iOS project that swaps the texture of a CCSprite via setTexture, like so: ``` [sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"Circle.png"]]; ``` However, the dimensions of the CCSprite's texture before and after the swap are different, and as a result, the Circle.png texture is getting cropped; stuck at the size of original texture (as the circle is larger). How can I adjust the size after swapping the Texture? (Related, but not helpful in solving this)