Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get CCSprite's size after changing scale

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;

like image 370
johnbakers Avatar asked Jan 31 '12 08:01

johnbakers


People also ask

How do you increase the size of a sprite?

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.

How do you change the size of a sprite in gamemaker?

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.

How do I resize a sprite in unity?

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.

How do you scale a sprite sheet?

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).


1 Answers

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.

like image 198
Ken Toh Avatar answered Nov 26 '22 21:11

Ken Toh