cocos2dx 3.2 getBoundingBox和getTextureRect

前端之家收集整理的这篇文章主要介绍了cocos2dx 3.2 getBoundingBox和getTextureRect前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Sprite* spTest = Sprite::create("CloseNormal.png");
spTest->setPosition(ptCenter);
this->addChild(spTest,1000,1000);

log("111");
Rect rect1 = spTest->getBoundingBox();
log("<<<%f,%f,%f",rect1.origin.x,rect1.origin.y,rect1.size.width,rect1.size.height);
Rect rect2 = spTest->getTextureRect();
log("<<<%f,rect2.origin.x,rect2.origin.y,rect2.size.width,rect2.size.height);

log("222");
spTest->setScale(0.2f);
Rect rect3 = spTest->getBoundingBox();
log("<<<%f,rect3.origin.x,rect3.origin.y,rect3.size.width,rect3.size.height);
Rect rect4 = spTest->getTextureRect();
log("<<<%f,rect4.origin.x,rect4.origin.y,rect4.size.width,rect4.size.height);

/*
cocos2d: 111
cocos2d: <<<300.000000,460.000000,40.000000,40.000000
cocos2d: <<<0.000000,0.000000,40.000000
cocos2d: 222
cocos2d: <<<316.000000,476.000000,8.000000,8.000000
cocos2d: <<<0.000000,40.000000
*/

总结 :原始尺寸是40 * 40,发现setScele后,getBoundingBox包围盒子矩形大小变了。

而getTextureRect大小始终是起始点从0,0开始,大小不变。

原文链接:https://www.f2er.com/cocos2dx/342917.html

猜你在找的Cocos2d-x相关文章