更改比例后如何获取 CCSprite 的大小 [英] How to get CCSprite's size after changing scale

查看:19
本文介绍了更改比例后如何获取 CCSprite 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不起作用:

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.

这篇关于更改比例后如何获取 CCSprite 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆