标题说明了一切。我想知道Sprite.getcontentsize,Sprite.gettexture和Sprite.getscale之间的区别。他们是如何使用的。 在这个问题之后我找不到任何资源。
答案 0 :(得分:1)
我们有例如名称为“test.png”的图像,宽度为100px,高度为200px。然后:
CCSprite testImage = CCSprite.sprite("test.png");
// print original image size
System.out.println("" + testImage.getContentSize().width + ", " + testImage.getContentSize().height); // print: 100, 200
// print actual image size
System.out.println("" + testImage.getBoundingBox().size.width + ", " + testImage.getBoundingBox().size.height); // print: 100, 200
// this will change resolution of image to half, so it will be drawn 2x smaller then original size
testImage.setScale(0.5f);
// print how many is image scaled
System.out.println("" + testImage.getScale()); // print: O.5
// print original image size
System.out.println("" + testImage.getContentSize().width + ", " + testImage.getContentSize().height); // print: 100, 200
// print actual image size
System.out.println("" + testImage.getBoundingBox().size.width + ", " + testImage.getBoundingBox().size.height); // print: 50, 100
testImage.gettexture()
可能会返回加载的纹理/图像,但我不知道,我从来不需要使用此功能。
答案 1 :(得分:1)
嗯,据我所知:
Sprite.getContentSize()
- >它将返回Sprite的大小(即宽度和高度)
Sprite.getScale()
- >它将返回缩小的分辨率(默认情况下,其值为1.如果要在运行时更改其大小,则使用此方法)
如果> 1,则精灵尺寸会更大,而<1将会缩小尺寸
注意:Sprite.getContentSize()
对缩放的精灵没有影响。它只会在高于或低于正常范围时提供原始精灵大小。
Sprite.getTexture()
- &gt;它将提供该精灵的图像。如果你想要创建具有相同纹理(图像)的另一个精灵,则使用它。
CCSprite newSprite = CCSprite.sprite(Sprite.getTexture());