This does not work:
CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame];
testscale.scale=0.5;
float starWidth=testscale.contentSizeInPixels.width;
CCLOG(@"contentpixels: %f contentsize: %f",starWidth, testscale.contentSize.width);
The two outputs in CCLOG both show the original pixel size of the sprite, not the size after scaling.
Is there a way to get it without doing this?...
float displayWidth=starWidth*testscale.scale;
You can make a Sprite bigger or smaller with the SET SIZE command. ACTIONS Toolkit - Scroll down to SPRITE SETTINGS - Set Size Block. Use a number less than 1 to make your sprite smaller and a number bigger than 1 to make the sprite larger.
If you take the height/width of your image, then divide it by the height/width you actually want you should be able to put it into image_yscale/image_xscale. So no matter what the sprites actual height is, it will go to 100 height. Then when you want it to go back to default height, set it to scale 1.
You can try changing the Pixels per Unit in the sprite sheets import settings. Just select the sprite sheet in the project window and you can change it in the inspector as shown in the image below: The lower the number the more screen space is going to be taken up by the sprite. Hope that helps.
If you just want to make the sprite bigger, it's as simple as opening your sprite sheet in a program like paint.net and using resize to change the height and width to whatever you want (make sure "maintain aspect ratio" is selected).
Use the boundingBox property of CCNode:
[testscale boundingBox].size.width
[testscale boundingBox].size.height
This should give you the width and height you want, taking into account any transformation (scaling, rotation) you have made to the sprite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With