gpt4 book ai didi

cocos2d-iphone - 更改比例后如何获取CCSprite的大小

转载 作者:行者123 更新时间:2023-12-04 10:20:29 25 4
gpt4 key购买 nike

这不起作用:

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

CCLOG 中的两个输出都显示 Sprite 的原始像素大小,而不是缩放后的大小。

有没有办法在不这样做的情况下获得它?...
float displayWidth=starWidth*testscale.scale;

最佳答案

使用 CCNode 的 boundingBox 属性:

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

考虑到您对 Sprite 所做的任何变换(缩放、旋转),这应该为您提供所需的宽度和高度。

关于cocos2d-iphone - 更改比例后如何获取CCSprite的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9076306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com