cocos2dx :getBoundingBox getContentSize getTextureRect

这是cocos2d-x代码看注释的解释 翻译的 不到之处谅解 后面在总结
getBoundingBox  // 返回一个AABB(axis-aligned bounding-box)在其父母的坐标系统。Returns an AABB (axis-aligned bounding-box) in its parent's coordinate system.
getContentSize  //节点容量大小
getTextureRect //返回精灵矩形的点

 

 

{
图片 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->getBoundingBox();
        Size size=pSpBox->getContentSize();
        Rect sizea=pSpBox->getTextureRect();
        CCLOG("BoundingBox(%f,%f,%f,%f)",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
        CCLOG("ContentSize(%f,%f)",size.width,size.height);
        CCLOG("TextureRect(%f,%f,%f,%f)",sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
    }
    pSpBox->setScale(0.5f);
    {
        CCLOG("B");
        Rect rect=pSpBox->getBoundingBox();
        Size size=pSpBox->getContentSize();
        Rect sizea=pSpBox->getTextureRect();
        CCLOG("BoundingBox(%f,%f,%f,%f)",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
        CCLOG("ContentSize(%f,%f)",size.width,size.height);
        CCLOG("TextureRect(%f,%f,%f,%f)",sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
    }

 

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,48.000000)
cocos2d: B
cocos2d: BoundingBox(468.000000,308.000000,24.000000,24.000000)
cocos2d: ContentSize(48.000000,48.000000)
cocos2d: TextureRect(0.000000,0.000000,48.000000,48.000000)
}

getBoundingBox  中得 Size.width .height  显示图片真实大小 (考虑缩放和不缩放)
getContentSize  纹理图片大小
getTextureRect  当前的纹理在总纹理的位置 (不考虑 缩放不缩放)
图片有缩放 就用 getBoundingBox ,不考虑缩放用 getContentSize

 

转载于:https://www.cnblogs.com/aibox222/p/8676139.html

你可能感兴趣的:(cocos2dx :getBoundingBox getContentSize getTextureRect)