I have created an atlas with all images I will use in a class. If this was a sprite created from an image, I would create it like
mySprite = [CCSprite spriteWithFile:@"white.png" rect:frame];
“white.png” is a 1×1 pixel image that I am stretching to cover the entire CCSprite size, that is defined by rect:frame on that API.
But in order to optimize I/O and memory, I put white.png in an atlas and my idea was to create it using
mySprite = [CCSprite spriteWithSpriteFrameName:@"white.png"];
but this will create a 1×1 pixel sprite. So, my idea was to create a category to extend CCSprite with these lines
@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;
}
so I could do this
mySprite = [CCSprite spriteWithSpriteFrameName:@"white.png"];
[mySprite resizeTo:frame.size];
and the 1×1 sprite would be stretched to cover the size I want.
The problem is that this is not working.
any clues? thanks.
It seems that in your case you can use CCLayerColor to create one-color layer. There is no need to use sprite for it.
About your question – make sure, that frame.size is not zero (CGSizeZero)