【问题标题】:How to get CCSprite's size after changing scale更改比例后如何获取 CCSprite 的大小
【发布时间】:2012-01-31 08:10:12
【问题描述】:

这不起作用:

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;

【问题讨论】:

    标签: cocos2d-iphone


    【解决方案1】:

    使用CCNode的boundingBox属性:

    [testscale boundingBox].size.width
    [testscale boundingBox].size.height
    

    这应该给你你想要的宽度和高度,考虑到你对精灵所做的任何变换(缩放、旋转)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 2013-03-19
      相关资源
      最近更新 更多