johnbakers
johnbakers

Reputation: 24750

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;

Upvotes: 7

Views: 5777

Answers (1)

Ken Toh
Ken Toh

Reputation: 3751

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.

Upvotes: 14

Related Questions