Reputation: 27394
I am creating a planet with the following code
CCSprite *planet = [CCSprite spriteWithFile:@"planet.png" rect:CGRectMake(0, 0, width, width)];
The planet itself is far larger than 48x48 so currently the image just clips. I would like the image to auto size into the container. How do I do this?
Upvotes: 0
Views: 1670
Reputation: 9089
assuming the container's width is 'width', a number greater than 0:
CCSprite *planet = [CCSprite spriteWithFile:@"planet.png"];
planet.scale=width/MAX(planet.contentSize.width,planet.contentSize.height);
Although if you are trying to get an icon sized planet (48 points) i suggest you create a texture for that rather than scaling down a very large image ... your mileage may vary on rendering quality when scaling down or up too much.
Upvotes: 3
Reputation: 8720
Use the scaleTo (or scaleBy) method and scale it according to the percentage difference from the original.
Upvotes: 1