加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-iphone – 如何在更改比例后获得CCSprite的大小

发布时间:2020-12-14 17:30:03 所属栏目:百科 来源:网络整理
导读:这不起作用: CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame]; testscale.scale=0.5;float starWidth=testscale.contentSizeInPixels.width; CCLOG(@"contentpixels: %f contentsize: %f",starWidth,testscale.contentSize.width); CCLOG
这不起作用:
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

这应该为您提供所需的宽度和高度,同时考虑到您对精灵所做的任何变换(缩放,旋转).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读