Cocos2d iphone 如何获得CCSprite';改变比例后的尺寸

Cocos2d iphone 如何获得CCSprite';改变比例后的尺寸,cocos2d-iphone,Cocos2d Iphone,这不起作用: CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame]; testscale.scale=0.5; float starWidth=testscale.contentSizeInPixels.width; CCLOG(@"contentpixels: %f contentsize: %f",starWidth, testscale.contentSize.width); CCLO

这不起作用:

CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame];
        testscale.scale=0.5;
float starWidth=testscale.contentSizeInPixels.width;
        CCLOG(@"contentpixels: %f contentsize: %f",starWidth, testscale.contentSize.width);
CCLOG中的两个输出都显示精灵的原始像素大小,而不是缩放后的大小

有没有办法不这样做就得到它


float displayWidth=starWidth*testscale.scale

使用CCNode的boundingBox属性:

[testscale boundingBox].size.width
[testscale boundingBox].size.height
考虑到对精灵所做的任何变换(缩放、旋转),这将为您提供所需的宽度和高度