更改比例后如何获取 CCSprite 的大小比例、大小、CCSprite

2023-09-06 10:24:57 作者:青衣剑客

这不起作用:

CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame];
        testscale.scale=0.5;
float starWidth=testscale.contentSizeInPixels.width;
        CCLOG(@"contentpixels: %f contentsize: %f",starWidth, testscale.contentSize.width);

CCLOG 中的两个输出都显示了精灵的原始像素大小,而不是缩放后的大小.

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;

推荐答案

使用CCNode的boundingBox属性:

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.

 
精彩推荐
图片推荐