getBoundingBox // 返回一个AABB(axis-aligned bounding-Box)在其父母的坐标系统。Returns an AABB (axis-aligned bounding-Box) in its parent's coordinate system.
getContentSize //节点容量大小
getTextureRect //返回精灵矩形的点
例子1
{
图片 Icon-48.png 这种图片 48 × 48 pixels 标准icon中得一个
Sprite *pSpBox=Sprite::create("Icon-48.png");
pSpBox->setPosition(Vec2(m_pWinSize.width*0.5,m_pWinSize.height*0.5));
pSpBox->setScale(0.2f);
addChild(pSpBox);
{
CCLOG(" A ");
Rect rect=pSpBox-> ();
Size size=pSpBox-> getContentSize sizea=pSpBox-> BoundingBox(%f,%f,%f) ",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
ContentSize(%f,size.width,size.height);
TextureRect(%f,sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
}
pSpBox->setScale(0.5f);
CCLOG("B");
cocos2d: A
cocos2d: BoundingBox(475.200012,315.200012,9.600006,9.600006)
cocos2d: ContentSize(48.000000,48.000000)
cocos2d: TextureRect(0.000000,0.000000,48.000000,51); font-family:Arial; font-size:14px; line-height:26px">cocos2d: B
cocos2d: BoundingBox(468.000000,308.000000,24.000000,24.000000)
}
例子2
图片 Icon-48.png 这种图片 48 × 48 pixels 标准icon中得一个
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("haohaoxuexi.plist");//把现有的icon图片整到一个大图中测试Sprite *pSpBox=Sprite::createWithSpriteFrameName("Icon-48.png");//create("Icon-48.png");
CCLOG(" B //输出结果
cocos2d: TextureRect(447.000000,1616.000000,51); font-family:Arial; font-size:14px; line-height:26px"> //"haohaoxuexi.plist" 中图片Icon-48.png 数据做参考
<key>Icon-48.png</key>
<dict>
<key>frame</key>
<string>{{447,1616},{48,48}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},48}}</string>
<key>sourceSize</key>
<string>{48,48}</string>
</dict>
应该都知道什么意思了,还是总结一下吧
getBoundingBox 中得 Size.width .height 显示图片真实大小 (考虑缩放和不缩放)
getContentSize 纹理图片大小
getTextureRect 当前的纹理在总纹理的位置 (不考虑 缩放不缩放)
图片有缩放 就用 getBoundingBox ,不考虑缩放用 getContentSize
看需求用哪个?
@H_301_137@getBoundingBox 中得 origin.x .y 本人也不知道什么意思,打印出来没有看懂。前做这点解释,知道后在更新
原文链接:https://www.f2er.com/cocos2dx/341015.html