【发布时间】:2012-06-19 19:40:42
【问题描述】:
我创建了一个图集,其中包含我将在课堂上使用的所有图像。如果这是从图像创建的精灵,我会像这样创建它
mySprite = [CCSprite spriteWithFile:@"white.png" rect:frame];
“white.png”是一个 1x1 像素的图像,我正在拉伸它以覆盖整个 CCSprite 大小,由该 API 上的 rect:frame 定义。
但为了优化 I/O 和内存,我将 white.png 放入了一个图集,我的想法是使用
mySprite = [CCSprite spriteWithSpriteFrameName:@"white.png"];
但这会创建一个 1x1 像素的精灵。所以,我的想法是创建一个类别来用这些行扩展 CCSprite
@implementation CCSprite (CCSprite_Resize)
-(void)resizeTo:(CGSize) theSize
{
CGFloat newWidth = theSize.width;
CGFloat newHeight = theSize.height;
float startWidth = self.contentSize.width;
float startHeight = self.contentSize.height;
float newScaleX = newWidth/startWidth;
float newScaleY = newHeight/startHeight;
self.scaleX = newScaleX;
self.scaleY = newScaleY;
}
所以我可以这样做
mySprite = [CCSprite spriteWithSpriteFrameName:@"white.png"];
[mySprite resizeTo:frame.size];
1x1 的精灵会被拉伸以覆盖我想要的大小。
问题是这不起作用。
有什么线索吗?谢谢。
【问题讨论】:
标签: cocos2d-iphone