我的iOS项目中有一段代码通过setTexture交换CCSprite的纹理,如下所示:
[sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"Circle.png"]];
但是,交换前后CCSprite纹理的尺寸不同,因此Circle.png纹理会被裁剪掉;卡在原始纹理的大小(因为圆圈较大)。
如何在交换纹理后调整大小?
答案 0 :(得分:9)
试试这个:
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)];
}
答案 1 :(得分:0)
您可以使用Sprite创建带有File构造函数的sprite。尺寸将自动设定