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

查看:447
本文介绍了如何获得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天全站免登陆